Presto SQL : Changing time zones using time zone string coming as a result of a query is not working

前端 未结 1 1117
栀梦
栀梦 2021-01-14 23:27

I am connecting to AWS Athena through Mode Analytics Platform and querying a table using its Query Engine ( which is based on Presto 0.172 ). This table public.zones

相关标签:
1条回答
  • 2021-01-15 00:22

    AT TIME ZONE accepts only literal or interval.

    Presto 320 adds with_timezone (for timestamp values) at_timezone (for timestamp with time zone values) exactly for this purpose.

    If you are using older Presto version (such as Athena as of this writing), you can use following workaround. You can cast your timestamp value to a varchar, concatenate with zone and cast to timestamp with time zone.

    presto> select cast(cast(t as varchar) || ' ' || zone as timestamp with time zone)
      from (values (timestamp '2017-06-01 12:34:56.789', 'US/Pacific')) x(t, zone);
                        _col0
    ---------------------------------------------
     2017-06-01 12:34:56.789 America/Los_Angeles
    (1 row)
    

    (Note: tested on Presto 320. If this doesn't work on Athena yet, let me know.)

    0 讨论(0)
提交回复
热议问题