例如,我有一个时间字符串'2012-10-31 01:00'(它是UTC,但字符串本身没有时区代码)
如何将其转换为纪元大整数?
我尝试了许多版本,但没有运气。
SELECT from_unixtime(cast('2012-10-31 01:00' as timestamp), 'Etc/UTC')
ERROR: function from_unixtime(timestamp without time zone, unknown) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 8
和
SELECT from_unixtime('2012-10-31 01:00', 'Etc/UTC')
相同错误
答案 0 :(得分:0)
timestamp
开始:CAST('2012-10-31 01:00' AS timestamp)
timestamp with time zone
:... AT TIME ZONE 'UTC'
double
):to_unixtime
bigint
):CAST(... * 1000 AS bigint)
。所有组合:
presto:default> SELECT CAST(to_unixtime(CAST('2012-10-31 01:00' AS timestamp) AT TIME ZONE 'UTC') * 1000 AS bigint);
_col0
---------------
1351641600000
(1 row)
(在Presto 320上测试)
您现在可以跳过AT TIME ZONE 'UTC'
转换,但是一旦我们fix Presto timestamp semantics,这将是必需的。因此,我建议您在查询中使用它。