我正在使用Athena Redshift SQL编写查询
我有两个不同的表格,我需要加入两列:unix_timestamp
和timestamp_code
unix_timestamp
存储为string
,如下所示:2018-04-01T10:05:52.047Z
timestamp_code
string
看起来像1514564885
我想将unix_timestamp
转换为`timestamp_code当前所在的格式。
我将如何做到这一点?
答案 0 :(得分:0)
转换为纪元:
SELECT EXTRACT(EPOCH FROM '2018-04-01T10:05:52.047Z'::TIMESTAMP);
-- date_part
--------------
-- 1522577152
从纪元转换为时间戳:
SELECT '1970-01-01'::TIMESTAMP + 1522577152 * INTERVAL '1 sec';
-- ?column?
-----------------------
-- 2018-04-01 10:05:52
https://docs.aws.amazon.com/redshift/latest/dg/r_EXTRACT_function.html https://docs.aws.amazon.com/redshift/latest/dg/r_Dateparts_for_datetime_functions.html