如何从时间戳(毫秒)转换为时代
例如,
Timestamp1 - 2019-10-20 11:43:47.298
Timestamp2 - 2019-10-20 11:43:47.469
使用EPOCH可以为两个时间戳提供相同的结果,即使它们是不同的时间戳(不同的毫秒)
查询-
extract('epoch' from timestamp '2019-10-20 11:43:47.298')::bigint * 1000
extract('epoch' from timestamp '2019-10-20 11:43:47.469')::bigint * 1000
Result - 1571571827000
我想要不同的结果,因为它们具有单独的时间戳记
答案 0 :(得分:2)
如果您不想失去毫秒精度,请不要强制转换为bigint
:
select
extract('epoch' from timestamp '2019-10-20 11:43:47.298') * 1000 epoch1,
extract('epoch' from timestamp '2019-10-20 11:43:47.469') * 1000 epoch2
epoch1 | epoch2 :------------ | :------------ 1571571827298 | 1571571827469