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

问题描述 投票:2回答:1

我如何从时间戳(具有毫秒)转换为纪元

例如,

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

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

sql timestamp amazon-redshift epoch
1个回答
1
投票

如果您不想失去毫秒精度,请不要转换为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 |时代2:------------ | :------------1571571827298 | 1571571827469
© www.soinside.com 2019 - 2024. All rights reserved.