4

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
s9gf4ult
  • 862
  • 6
  • 20

2 Answers2

2

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.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
-1

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)
Chris Farmiloe
  • 13,935
  • 5
  • 48
  • 57