代码之家  ›  专栏  ›  技术社区  ›  daydayup

Presto将没有时区的时间戳转换为epoch

  •  0
  • daydayup  · 技术社区  · 5 年前

    如何将其转换为大整数?

    我试过很多版本,只是运气不好。

    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 回复  |  直到 5 年前
        1
  •  1
  •   Piotr Findeisen    5 年前
    • 从转换为开始 timestamp : CAST('2012-10-31 01:00' AS timestamp)
    • timestamp with time zone : ... AT TIME ZONE 'UTC'
    • double ): to_unixtime
    • 然后转换为epoch millis( 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 ,这是需要的。因此,我建议您在查询中使用此选项。