gpt4 book ai didi

带有时间戳字段的 PostgreSQL 神秘主义

转载 作者:行者123 更新时间:2023-11-29 13:03:55 25 4
gpt4 key购买 nike

我有带有timestamp with time zone 的PostgreSQL 数据库表名为 published_date 的字段。

我使用 psql -U postgres dbname 命令访问我的数据库。

当我尝试通过命令更新 published_date 字段值时:

UPDATE mytable SET published_date='PUBLISHED_DATE' WHERE id=3;

我得到了相应 PUBLISHED_DATE 的以下结果:

SOURCE              -> RESULT

2013-01-16 20:00:00 -> 2013-01-16 20:00:00+00 (WELL)
2013-02-16 20:00:00 -> 2013-02-16 20:00:00+00 (WELL)
2013-03-16 20:00:00 -> 2013-03-16 20:00:00+00 (WELL)
2013-04-16 20:00:00 -> 2013-04-16 20:00:00+01 (STRANGE!)
2013-05-16 20:00:00 -> 2013-05-16 20:00:00+01 (STRANGE!)
2013-06-16 20:00:00 -> 2013-06-16 20:00:00+01 (STRANGE!)
2013-07-16 20:00:00 -> 2013-07-16 20:00:00+01 (STRANGE!)
2013-08-16 20:00:00 -> 2013-08-16 20:00:00+01 (STRANGE!)
2013-09-16 20:00:00 -> 2013-09-16 20:00:00+01 (STRANGE!)
2013-10-16 20:00:00 -> 2013-10-16 20:00:00+01 (STRANGE!)
2013-11-16 20:00:00 -> 2013-11-16 20:00:00+00 (WELL)
2013-12-16 20:00:00 -> 2013-12-16 20:00:00+00 (WELL)

数据库中有UTC时区:

=> SHOW timezone;
TimeZone
----------
UTC
(1 row)

和系统:

$ date
Tue Dec 17 00:14:12 GMT 2013

PostgreSQL 版本为 9.2.4

相同版本的 postgres 在另一台机器上安装了相同的标志,运行良好!很奇怪。

最佳答案

这是正常行为,PostgreSQL 在输出带时区的时间戳(内部确实存储为 UTC)时会尝试容纳用户。我假设你在英国,你看到的是它在夏季和冬季之间的变化。从手册中强调:

For timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the system's timezone parameter, and is converted to UTC using the offset for the timezone zone.

When a timestamp with time zone value is output, it is always converted from UTC to the current timezone zone, and displayed as local time in that zone. To see the time in another time zone, either change timezone or use the AT TIME ZONE construct (see Section 9.9.3).

关于带有时间戳字段的 PostgreSQL 神秘主义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20623686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com