Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id ADD35A684E0 for ; Mon, 21 May 2012 20:13:47 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SWbnL-0008BK-5C for pgsql-bugs@postgresql.org; Mon, 21 May 2012 23:13:47 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q4LNDS92009303; Mon, 21 May 2012 19:13:28 -0400 (EDT) To: mw@hesotech.de cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6656: Wrong timestamptz + interval calculation In-reply-to: References: Comments: In-reply-to mw@hesotech.de message dated "Mon, 21 May 2012 18:38:29 -0000" Date: Mon, 21 May 2012 19:13:28 -0400 Message-ID: <9302.1337642008@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/131 X-Sequence-Number: 33102 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