Can you use a column for the timezone parameter of AT TIME ZONE in Presto / Athena?

时光毁灭记忆、已成空白 提交于 2019-11-26 22:12:16

问题


Here is an operation you can perform in Athena-

SELECT date_utc AT TIME ZONE 'America/Chicago'
FROM
(
  SELECT TIMESTAMP '2018-09-09 12:00:00' as date_utc

) x;

In other sql engines you can change America/Chicago to a column-

SELECT date_utc AT TIME ZONE x.timezone
FROM
(
  SELECT
    TIMESTAMP '2018-09-09 12:00:00' as date_utc,
    'America/Chicago' as timezone

) x;

In Athena you get-

line 1:30: no viable alternative at input 'time zone x'

Should it be possible to use x.timezone in Athena? This seems like a bug.


回答1:


It indeed looks like a bug in the engine. What is interesting however is, that the underlying function works with a column parameter. So you can use this as a workaround.

SELECT at_timezone(date_utc,x.timezone)
FROM
(
  SELECT
    TIMESTAMP '2018-09-09 12:00:00' as date_utc,
    'America/Chicago' as timezone

) x;



回答2:


Adding some additional context to the the correct answer above: AT_TIMEZONE function is not documented in presto docs. When someone uses timestamp AT time zone tz , its actually AT_TIMEZONE function that gets called. It appears to be an internal function, which some folks were already using. Here is an issue discussing it: https://github.com/prestodb/presto/issues/5162

The syntax appears to be AT_TIMEZONE(date_field, tz_field_or_string)



来源:https://stackoverflow.com/questions/52446184/can-you-use-a-column-for-the-timezone-parameter-of-at-time-zone-in-presto-athe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!