You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CnosDB中向毫秒精度数据库写入纳秒时间戳的异常问题

问题原因与解决方法

问题根源

你创建的数据库精度为毫秒(ms),但写入的是纳秒级时间戳(1682049219172428000),CnosDB会自动将时间戳截断到数据库指定的精度级别,导致纳秒部分丢失,最终查询结果和预期不符。

解决方案

方案1:将数据库精度改为纳秒

如果需要保留纳秒级时间精度,重新创建数据库时指定precision 'ns':

create database ms with precision 'ns';
create table ms_t (value BIGINT,tags(str));
insert into ms_t (time,str,value) values (1682049219172428000,'asd',1);

写入后查询,时间戳会完整保留纳秒信息。

方案2:写入时转换为毫秒级时间戳

如果必须使用毫秒精度的数据库,将纳秒时间戳除以1000000转换为毫秒级后再写入:

insert into ms_t (time,str,value) values (1682049219172,'asd',1);

此时写入的时间与数据库精度匹配,查询结果会符合预期。

验证查询

执行以下语句确认结果:

select * from ms_t;

内容的提问来源于stack exchange,提问作者cosmic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 15:22:07