简体   繁体   English

PostgreSQL将时区信息存储在TIMESTAMP WITH TIMEZONE中吗?

[英]Postgresql stores timezone information in TIMESTAMP WITH TIMEZONE?

I'm trying to understand how PostgreSQL handles TIMESTAMP WITH TIMEZONE type, and I 'm running into the discrepancy between theory and practice. 我试图了解PostgreSQL如何处理带有TIMEZONE类型的TIMESTAMP,并且遇到了理论与实践之间的差异。

According to the documentation and other stack overflow posts, 根据文档和其他堆栈溢出文章,

For timestamp with time zone, the internally stored value is always in UTC ... When a timestamp with time zone value is output, it is always converted from UTC to the current timezone zone. 对于带时区的时间戳,内部存储的值始终以UTC表示...当输出带时区的时间戳时,始终将其从UTC转换为当前时区。

I believe this means that all timestamps in any given SELECT statement will be in the same/current timezone. 我相信这意味着任何给定SELECT语句中的所有时间戳都将在相同/当前时区中。 However, this is what I see: 但是,这是我看到的: 在此处输入图片说明

interview_timestamp is TIMESTAMP WITH TIMEZONE. 面试时间戳是TIMESTAMP WITH TIMEZONE。 This blows my mind. 这让我大吃一惊。

It is strange that you sometimes see a time zone offset and sometimes not, I would blame that on the GUI you are using. 奇怪的是,您有时会看到时区偏移,而有时却看不到,我会怪您正在使用的GUI。 Try with psql and see how the data look there. 尝试使用psql ,看看那里的数据如何。

The offset “-05:44:38” is perfectly normal, since time zones were introduced in the late 19th century and local solar time is used before that. 偏移“ -05:44:38”是完全正常的,因为时区是在19世纪后期引入的,并且在此之前使用了当地的太阳时。

Just for the record, this was really a client thing and it because an offset from UTC depends on the time of year (EDT: -4, EST: -5). 仅作记录,这实际上是客户的事情,这是因为与UTC的偏移量取决于一年中的时间(EDT:-4,EST:-5)。 Offset "-05:44:38" is correct too, this is offset in TZ database for EDT/EST for years prior to 1883. 偏移“ -05:44:38”也是正确的,这在1883年之前的EDT / EST的TZ数据库中已被偏移。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM