I have a python script that insert hourly readings into a postgres db. It is failing in 2010-03-28. How is postgres interpreting both 01:00:00 and 02:00:00 as 02:00:00. what am I doing wrong (ps: works for other dates prior to this)
select to_timestamp('28/03/2010 01:00:00','DD/MM/YYYY HH24:MI:SS');
to_timestamp
------------------------
2010-03-28 02:00:00+01
(1 row)
select to_timestamp('28/03/2010 02:00:00','DD/MM/YYYY HH24:MI:SS');
to_timestamp
------------------------
2010-03-28 02:00:00+01
(1 row)
Nothing wrong.
As commented by a_horse_with_no_name, what you are seeing is the effect of Daylight Saving Time. On 2 AM CET on March 28th, the clock skips one hour and goes directly to 3 AM. I assume that your timezone is
UTC+01
, so you are seeing this on 1 AM > 2 AM.That particular day only has 23 hours: both dates do represent the same point in time, which is what you are seeing in the results generated by
to_timestamp()
.Extracting the corresponding epochs, you can also see that the results are identical:
This is just one of the many tricks involved when working with dates. There is not much you can do about that from Postgres' perspective: it is on your application to handle that.