Presto SQL:使用作为查询结果出现的时区字符串更改时区不起作用
Presto SQL : Changing time zones using time zone string coming as a result of a query is not working
我正在通过模式分析平台连接到 AWS Athena,并使用其查询引擎(基于 Presto 0.172)查询 table。这个 table public.zones
的时区信息存储在我感兴趣的某些地区的名为 time_zone
的列中,存储为 varchar
.
例如,如果我输入:
SELECT time_zone
FROM public.zones
LIMIT 4;
我得到(如预期):
time_zone
----------
US/Pacific
US/Eastern
US/Eastern
US/Eastern
我可以运行这个测试查询:
SELECT
timestamp '2017-06-01 12:34:56.789' AT TIME ZONE 'US/Eastern' AS time_eastern,
time_zone
FROM public.zones
LIMIT 4;
我得到(如预期的那样)
time_eastern time_zone
---------------------------------- ----------
2017-06-01 08:34:56.789 US/Eastern US/Pacific
2017-06-01 08:34:56.789 US/Eastern US/Eastern
2017-06-01 08:34:56.789 US/Eastern US/Eastern
2017-06-01 08:34:56.789 US/Eastern US/Eastern
现在,我想在不同的时区中表示相同的时间字符串 '2017-06-01 12:34:56.789'
,我从时区 table 查询。我预计以下查询 运行。 (在 PostgreSQL 上 运行)。
SELECT
timestamp '2017-06-01 12:34:56.789' AT TIME ZONE time_zone AS time_custom,
time_zone
FROM public.zones
LIMIT 4;
我收到以下错误:
[Simba][AthenaJDBC](100071) An error has been thrown from the AWS Athena client.
line 2:52: no viable alternative at input 'TIME ZONE time_zone'
这在 Presto SQL/AWS Athena 查询引擎中不起作用的原因是什么?
任何人都可以提出任何解决方法或者我的语法错误是什么?
AT TIME ZONE
只接受文字或间隔。
Presto 320 添加 with_timezone
(for timestamp
values) at_timezone
(对于 timestamp with time zone
值)正是为此目的。
如果您使用的是较旧的 Presto 版本(例如撰写本文时的 Athena),则可以使用以下解决方法。您可以将时间戳值转换为 varchar
,与区域连接并转换为 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)
(注意:已在 Presto 320 上测试。如果这在 Athena 上还不起作用,请告诉我。)
我正在通过模式分析平台连接到 AWS Athena,并使用其查询引擎(基于 Presto 0.172)查询 table。这个 table public.zones
的时区信息存储在我感兴趣的某些地区的名为 time_zone
的列中,存储为 varchar
.
例如,如果我输入:
SELECT time_zone
FROM public.zones
LIMIT 4;
我得到(如预期):
time_zone
----------
US/Pacific
US/Eastern
US/Eastern
US/Eastern
我可以运行这个测试查询:
SELECT
timestamp '2017-06-01 12:34:56.789' AT TIME ZONE 'US/Eastern' AS time_eastern,
time_zone
FROM public.zones
LIMIT 4;
我得到(如预期的那样)
time_eastern time_zone
---------------------------------- ----------
2017-06-01 08:34:56.789 US/Eastern US/Pacific
2017-06-01 08:34:56.789 US/Eastern US/Eastern
2017-06-01 08:34:56.789 US/Eastern US/Eastern
2017-06-01 08:34:56.789 US/Eastern US/Eastern
现在,我想在不同的时区中表示相同的时间字符串 '2017-06-01 12:34:56.789'
,我从时区 table 查询。我预计以下查询 运行。 (在 PostgreSQL 上 运行)。
SELECT
timestamp '2017-06-01 12:34:56.789' AT TIME ZONE time_zone AS time_custom,
time_zone
FROM public.zones
LIMIT 4;
我收到以下错误:
[Simba][AthenaJDBC](100071) An error has been thrown from the AWS Athena client.
line 2:52: no viable alternative at input 'TIME ZONE time_zone'
这在 Presto SQL/AWS Athena 查询引擎中不起作用的原因是什么?
任何人都可以提出任何解决方法或者我的语法错误是什么?
AT TIME ZONE
只接受文字或间隔。
Presto 320 添加 with_timezone
(for timestamp
values) at_timezone
(对于 timestamp with time zone
值)正是为此目的。
如果您使用的是较旧的 Presto 版本(例如撰写本文时的 Athena),则可以使用以下解决方法。您可以将时间戳值转换为 varchar
,与区域连接并转换为 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)
(注意:已在 Presto 320 上测试。如果这在 Athena 上还不起作用,请告诉我。)