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.
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;
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)