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

如何在AWS Timestream中将bigint转换为timestamp解决查询报错

解决方案

错误原因

Timestream的time字段默认为timestamp类型,不支持直接与bigint类型的Unix时间戳做等值比较,也不支持通过cast直接将bigint强转为timestamp类型。

正确实现方法

你提供的1637339664248是毫秒级Unix时间戳,直接调用Timestream内置的from_milliseconds()函数转换即可:

select * FROM "data-api-timestream-test"."table_test" where time = from_milliseconds(1637339664248)

其他精度时间戳转换参考

如果你的时间戳精度不同,可以对应使用以下内置函数:

  • 秒级Unix时间戳:使用from_unixtime()函数
  • 微秒级Unix时间戳:使用from_microseconds()函数
  • 纳秒级Unix时间戳:使用from_nanoseconds()函数

注意事项

不建议将time字段通过函数转换后再和数值比较,示例如下:

-- 不推荐,会导致time字段的索引失效,查询性能大幅下降
select * FROM "data-api-timestream-test"."table_test" where to_milliseconds(time) = 1637339664248

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 20:45:00