如何使用 Presto 中另一列的秒数来增加时间戳?

How to increment timestamp using number of seconds from another column in Presto?

我的 Presto table 中有两列(称之为 table_a):time_clmndelta_clmn。它们各自的数据类型是:timestamp和bigint。我想将 time_clmn 增加 delta_clmn 但返回错误:

select time_clmn + interval cast(delta_clmn as varchar) second as new_field
from table_a

这是错误信息:

SQL Error [1]: Query failed (#20190820_164600_02306_kzuv6): line 2:20: mismatched input 'cast'. Expecting: '%', '*', '+', '-', '.', '/', 'AT', '[', '||', <expression>

有解决办法吗?

抱歉,我找不到 Presto 的在线演示来说明我的示例。

您可以像这样使用 date_add 函数:

SELECT date_add('SECOND', delta_clmn, time_clmn)
FROM (VALUES (TIMESTAMP '2019-08-20 18:50', 42)) t(time_clmn, delta_clmn);
          _col0
-------------------------
 2019-08-20 18:50:42.000
(1 row)