PostgreSql: Getting strange-formated “timestamp with time zone”

回眸只為那壹抹淺笑 提交于 2019-12-23 15:16:28

问题


I am inserting into the table with field type "timestamp with time zone" string "1858-11-17 01:09:05+0000" and getting back strage formated value "05:11:29+04:02:24".

Here is session

test=> create table ddtbl (val timestamp with time zone);
CREATE TABLE
test=> insert into ddtbl (val) values ('1858-11-17 01:09:05+0000');
INSERT 0 1
test=> select * from ddtbl;
             val              
------------------------------
 1858-11-17 05:11:29+04:02:24

Why is this happening and what is "+04:02:24" here ?

UPD: PostgreSQL version

% psql --version
psql (PostgreSQL) 9.2.4

UPD2: Local timezone

% date +%Z
YEKT
% date +%z
+0600

回答1:


This is an effect of the time zone. Before early 20th century many countries (like Germany or Russia) had completely different regimes like "mean solar time" which would not translate cleanly to UTC.

Therefore a time in time zone 0 (GMT at the time, as there was no UTC yet) would have an odd time offset when represented as local time for Yekaterinburg (Russia).

+04:02:24 is the actual offset as compared to UTC.




回答2:


It is interpreting your input value is UTC.

psql=# select cast('1858-11-17 01:09:05 UTC' as timestamp with time zone);
      timestamptz       
------------------------
 1858-11-17 01:09:05+00
(1 row)


psql=# select cast('1858-11-17 01:09:05 BRT' as timestamp with time zone);
      timestamptz       
------------------------
 1858-11-17 04:09:05+00
(1 row)

The two values are the just different representations of the same timestamp.

psql=# select cast('1858-11-17 05:11:29+04:02:24' as timestamp with time zone) = cast('1858-11-17 01:09:05+0000' as timestamp with time zone);
 ?column? 
----------
 t
(1 row)


来源:https://stackoverflow.com/questions/16572455/postgresql-getting-strange-formated-timestamp-with-time-zone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!