Presto 将时间戳转换为纪元

Presto convert timestamp to epoch

在redshift中,我可以做这样的事情

date_part(epoch, '2019-03-07 10:17:03.000000') 并且会 return 1551953823。我如何在 Presto 中执行此操作?

您可以使用 to_unixtime:

presto> select to_unixtime(timestamp '2019-03-07 10:17:03');
     _col0
---------------
 1.551953823E9
(1 row)

或使用date_diff从纪元时间戳中减去时间戳:

presto> select date_diff('second', timestamp '1970-01-01', timestamp '2019-03-07 10:17:03');
   _col0
------------
 1551953823
(1 row)

注意to_unixtime returns一个double表示秒数加毫秒作为小数部分。如果你只想要秒数,你可以将结果转换为 BIGINT:

presto> select cast(to_unixtime(timestamp '2019-03-07 10:17:03') as bigint);
   _col0
------------
 1551953823
(1 row)