【问题标题】:Aginity Workbench for Redshift - to_timestamp conversion issueAginity Workbench for Redshift - to_timestamp 转换问题
【发布时间】:2017-10-23 15:37:09
【问题描述】:

在 Aginity Workbench for AWS Redshift 上使用函数 to_timestamp() 时遇到问题。出于某种我不明白的原因,我尝试创建的时间戳增加了 2 小时。

我一直在寻找解决方案,但找不到类似的东西,有人可以帮我解决这个问题吗?


以下代码:

select
'2017-10-17 10:30:00' test,
to_timestamp('2017-10-17 10:30:00','YYYY-MM-DD HH24:MI:SS') test_converted

检索:

测试 = 2017-10-17 10:30:00

test_converted = 2017-10-17 12:30:00

【问题讨论】:

  • 看起来像一个时区的东西。你是UTC+2吗? '2017-10-17 10:30:00'::timestamp 和 '2017-10-17 10:30:00'::timestamptz 和 '2017-10-17 10:30:00' 你会得到什么: :timestamptz 在时区 'UTC'
  • 同意,'2017-10-17 10:30:00'::timestamptz 给出 '2017-10-17 12:30:00' 和 '2017-10-17 10:30:00 '::timestamptz 在时区'UTC' 给我'2017-10-17 10:30:00'。 “::”在做什么?如果 XX::timestamp 等于 to_timestamp(XX,'YYYY-MM-DD HH24:MI:SS') 那么它解决了我的问题。
  • 请在下方查看我的回答,如果您需要,请“接受”

标签: sql amazon-redshift aginity


【解决方案1】:

您可以使用 :: 在 postgres 和 redshift 中转换类型,因此您的代码将是

select '2017-10-17 10:30:00'::timestamp;

这将解决您的问题。

(我认为您之前的代码正在转换为本地时区)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 2021-06-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 2015-10-23
    相关资源
    最近更新 更多