问题描述
我想查询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
值之间进行恒定转换