在redshift中,我可以做类似的事情
date_part(epoch, '2019-03-07 10:17:03.000000')
,它将返回1551953823
。如何在Presto中做到这一点?
答案 0 :(得分:3)
您可以使用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
返回一个代表秒数和毫秒数的小数部分。如果只需要几秒钟,则可以将结果强制转换为BIGINT
:
presto> select cast(to_unixtime(timestamp '2019-03-07 10:17:03') as bigint);
_col0
------------
1551953823
(1 row)