postgresql - 如何在具有长格式时间戳的列上以日期作为输入运行 postgres 查询
问题描述
我想查询 postgres 数据库表,该表的时间戳为长毫秒。但我有这样的日期格式“yyyy-MM-dd HH:mm:ssZ”的时间。如何将此日期格式转换为长毫秒来运行查询?
解决方案
您可以将 long 值转换为适当的时间戳:
select *
from the_table
where to_timestamp(the_millisecond_column / 1000) = timestamp '2020-10-05 07:42'
或者从时间戳值中提取秒数:
select *
from the_table
where the_millisecond_column = extract(epoch from timestamp '2020-10-05 07:42') * 1000
然而,更好的解决方案是将该列转换为正确的timestamp
列,以避免(毫秒)和正确timestamp
值之间的不断转换
推荐阅读
- timer - 计时器值之间的差异与预期不同
- java - 杰克逊:从 JSON 数组中获取没有 id 的单个值
- java - 在 Spring mvc 中使用 html 文件发送 dto
- java - 如何将生成的 AES 密钥从 Diffie-Hellman 类添加到我使用该密钥的类
- java - 如何使 keycloak 与嵌入式码头一起工作?
- android - Gitlab 添加带有第三方 api 密钥和凭据的文件
- c# - 当某些 $type 未知时,使用 TypeNameHandling 反序列化对象集的最佳方法
- ios - 通过 Firebase 推送通知不会出现在 iOS 上,而应用程序在后台
- angular - Angular:当我删除列表中的对象时禁用滚动到顶部
- ionic-framework - 如何增加 Ionic 3 项目的版本号?