我已经将一个名为staging
的表导入到我的PostgreSQL数据库中.时间数据作为格式为2020-01-31T00:01:59Z
的文本列timestamp
存储在该表中.我知道这个数据是UTC的,尽管这个信息在文本字符串中并不明确.我想将此信息存储在带有时区的时间戳列中,但我找不到一种方法来告诉PostgreSQL此数据是UTC格式的.
如果我运行一个简单的to_timestamp()
,数据被假定为在我的本地时间.例如,请参阅此调用:
SELECT timestamp AS textoriginal,
to_timestamp(timestamp, 'YYYY-MM-DD"T"HH24:MI:SS"Z"') AS to_timestamp,
to_timestamp(timestamp, 'YYYY-MM-DD"T"HH24:MI:SS"Z"') AT TIME ZONE 'UTC' AS perceivedutc
FROM staging
LIMIT 5
|textoriginal |to_timestamp |perceivedutc |
|--------------------|------------------------|------------------------|
|2015-12-11T11:00:43Z|Dec 11 2015 11:00:43 +01|Dec 11 2015 10:00:43 |
|2015-12-11T11:08:38Z|Dec 11 2015 11:08:38 +01|Dec 11 2015 10:08:38 |
|2015-12-11T11:12:19Z|Dec 11 2015 11:12:19 +01|Dec 11 2015 10:12:19 |
|2015-12-11T11:16:24Z|Dec 11 2015 11:16:24 +01|Dec 11 2015 10:16:24 |
|2015-12-11T11:20:30Z|Dec 11 2015 11:20:30 +01|Dec 11 2015 10:20:30 |
如何向PostgreSQL声明此字符串为UTC格式?