Presto:将时间戳 w/TZ 转换为普通时间戳而不转换为 UTC

Presto: Cast timestamp w/TZ to plain timestamp WITHOUT converting to UTC

Presto 中的此查询:

select *, 
  cast(ts_w_tz as timestamp) as ts, 
  cast(substr(cast(ts_w_tz as varchar), 1, 23) as timestamp) as local_ts_workaround 
from (select timestamp '2018-02-06 23:00:00.000 Australia/Melbourne' as ts_w_tz);

Returns:

                   ts_w_tz                   |           ts            |   local_ts_workaround   
---------------------------------------------+-------------------------+-------------------------
 2018-02-06 23:00:00.000 Australia/Melbourne | 2018-02-06 12:00:00.000 | 2018-02-06 23:00:00.000

如您所见,将带有时区的时间戳转换为时间戳的行为导致时间戳被转换回 UTC 时间(例如 ts)。根据 local_ts_workaround.

,IMO 正确的行为应该是 return 时间戳的 'wall reading'

我发现有很多帖子说 Presto 对此的处理是错误的,并且不符合 SQL 标准,并且正在修复中。但与此同时,这是一个主要的痛苦,因为效果似乎没有内置的方法来获取没有时区的本地化时间戳(根据 local_ts_workaround)。

显然,我现在有字符串转换解决方法,但这看起来很糟糕。我想知道是否有人有更好的解决方法或者可以指出我遗漏的地方?

谢谢。

select cast(from_iso8601_timestamp('2018-02-06T23:00:00.000Z') as timestamp)

似乎没有很好的解决方案,但在以前的答案的基础上,我更喜欢这个......参见 date_format_workaround 专栏:

select *,
  cast(from_iso8601_timestamp(date_format(ts_w_tz, '%Y-%m-%dT%H:%i:%s')) as timestamp) as date_format_workaround,
  cast(ts_w_tz as timestamp) as ts,
  cast(substr(cast(ts_w_tz as varchar), 1, 23) as timestamp) as local_ts_workaround
from (select timestamp '2018-02-06 23:00:00.000 Australia/Melbourne' as ts_w_tz);