【问题标题】:How can I convert an integer representing EPOCH time to a timestamp in Athena (Presto)?如何将表示 EPOCH 时间的整数转换为 Athena (Presto) 中的时间戳?
【发布时间】:2019-10-01 00:55:25
【问题描述】:

我有一个表,其中日期时间存储为 varchar,但代表 EPOCH 时间(例如 1556895150)。如何让该值被识别为 Athena 中的时间戳/使用 Presto?像 dateadd 函数这样的东西可以工作,但 Athena 没有 dateadd(我设想像 dateadd('second',expressoin,'1970-01-01 00:00:00')。一个简单的 CAST(expressoin as type)没有在这里工作,因为 EPOCH 不是公认的日期时间数据类型。

【问题讨论】:

    标签: sql datetime epoch presto amazon-athena


    【解决方案1】:

    你可以使用from_unixtime():

    presto> select from_unixtime(1556895150);
              _col0
    -------------------------
     2019-05-03 07:52:30.000
    (1 row)
    

    【讨论】:

    • 不起作用,因为1556895150 存储为 varchar
    • 在调用from_unixtime之前将纪元转换为bigint:CAST(epoch as bigint)
    猜你喜欢
    • 2020-11-16
    • 2016-02-13
    • 2019-12-24
    • 2017-11-15
    • 2013-01-04
    • 2017-03-23
    • 2018-11-29
    • 2020-01-19
    • 2020-05-07
    相关资源
    最近更新 更多