如何在 Redshift 中将时间戳(以毫秒为单位)转换为 EPOCH

How do I convert Timestamp (having milliseconds) to EPOCH in Redshift

如何将时间戳(以毫秒为单位)转换为纪元

例如,

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

我想要不同的结果,因为它们有不同的时间戳

如果您不想失去毫秒精度,请不要转换为 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

Demo on DB Fiddle:

epoch1        | epoch2       
:------------ | :------------
1571571827298 | 1571571827469