Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 886
micah Avatar asked Oct 17 '25 06:10

micah


1 Answers

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;
like image 83
jens walter Avatar answered Oct 19 '25 22:10

jens walter