Can you use a column for the timezone parameter of

2019-01-29 10:17发布

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.

2条回答
做自己的国王
2楼-- · 2019-01-29 10:39

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;
查看更多
The star\"
3楼-- · 2019-01-29 10:58

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)

查看更多
登录 后发表回答