From: Tom Lane <tgl@sss.pgh.pa.us>
To: mw@hesotech.de
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6656: Wrong timestamptz + interval calculation
Date: Mon, 21 May 2012 19:13:28 -0400
Message-ID: <9302.1337642008@sss.pgh.pa.us> (raw)
In-Reply-To: <E1SWXUz-0002tb-Qc@wrigleys.postgresql.org>
References: <E1SWXUz-0002tb-Qc@wrigleys.postgresql.org>
mw@hesotech.de writes:
> When I execute the statement
> select timestamptz '2012-03-01 00:00:00+00' + interval '1 month'
> I expect the result:
> "2012-04-01 02:00:00+02"
> but postgres returns:
> "2012-04-01 01:00:00+02"
This does not look like a bug to me. You did not say what time zone you
are using, but I bet it is one that is UTC+1 in the winter and switches
to UTC+2 during March. For instance, if I try this in Europe/Amsterdam
zone I get:
regression=# set timezone = 'Europe/Amsterdam';
SET
regression=# select now();
now
-------------------------------
2012-05-22 01:04:52.556207+02
(1 row)
regression=# select timestamptz '2012-03-01 00:00:00+00';
timestamptz
------------------------
2012-03-01 01:00:00+01
(1 row)
The above is correct since midnight UTC corresponds to 1AM Amsterdam
winter time ...
regression=# select timestamptz '2012-03-01 00:00:00+00' + interval '1 month';
?column?
------------------------
2012-04-01 01:00:00+02
(1 row)
... and adding '1 month' to a timestamptz is defined to produce the same
local time, so this is the correct result.
If you don't want such behavior, you could use a timezone setting that
has no DST transitions. Or possibly you want to do the arithmetic with
the type timestamp without time zone, rather than with time zone.
Or you could express the interval to be added as so many
hours/minutes/seconds, rather than using the variable-size units of
days/weeks/months/years.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, mw@hesotech.de
Subject: Re: BUG #6656: Wrong timestamptz + interval calculation
In-Reply-To: <9302.1337642008@sss.pgh.pa.us>
References: <E1SWXUz-0002tb-Qc@wrigleys.postgresql.org> <9302.1337642008@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox