Reputation: 23
How do I convert from timestamp (having milliseconds) to epoch
For E.g.,
Timestamp1 - 2019-10-20 11:43:47.298
Timestamp2 - 2019-10-20 11:43:47.469
Using EPOCH gives the same results for both the timestamps, even though they are different timestamps (different milliseconds)
Query-
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
I want different results as they have separate timestamps
Upvotes: 2
Views: 2129
Reputation: 222702
Just don't cast to bigint
if you don't want to lose the millisecond precision:
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
Upvotes: 2