pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #6656: Wrong timestamptz + interval calculation
2+ messages / 2 participants
[nested] [flat]
* BUG #6656: Wrong timestamptz + interval calculation
@ 2012-05-21 18:38 mw@hesotech.de
0 siblings, 1 reply; 2+ messages in thread
From: mw@hesotech.de @ 2012-05-21 18:38 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 6656
Logged by: Marcus Wirsing (Hesotech GmbH)
Email address: mw@hesotech.de
PostgreSQL version: 9.1.3
Operating system: Windows 7 64Bit
Description:
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"
My local time zone is UTC+1.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #6656: Wrong timestamptz + interval calculation
@ 2012-05-21 23:13 Tom Lane <tgl@sss.pgh.pa.us>
parent: mw@hesotech.de
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2012-05-21 23:13 UTC (permalink / raw)
To: mw@hesotech.de; +Cc: pgsql-bugs
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2012-05-21 23:13 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-05-21 18:38 BUG #6656: Wrong timestamptz + interval calculation mw@hesotech.de
2012-05-21 23:13 ` Tom Lane <tgl@sss.pgh.pa.us>
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