Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bceWE-0001Ow-66 for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Aug 2016 20:11:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bceWD-0005qX-P0 for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Aug 2016 20:11:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bceVZ-00057g-QQ for pgsql-bugs@postgresql.org; Wed, 24 Aug 2016 20:10:45 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bceVX-0006QN-67 for pgsql-bugs@postgresql.org; Wed, 24 Aug 2016 20:10:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u7OKAeUh031169; Wed, 24 Aug 2016 16:10:40 -0400 From: Tom Lane To: Andrew Gierth cc: pablopumarino@gmail.com, pgsql-bugs@postgresql.org Subject: Re: BUG #14294: Problem in generate series between dates In-reply-to: <87oa4i9d8w.fsf@news-spur.riddles.org.uk> References: <20160824182920.15681.52285@wrigleys.postgresql.org> <28256.1472064660@sss.pgh.pa.us> <87oa4i9d8w.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Wed, 24 Aug 2016 20:40:45 +0100" Date: Wed, 24 Aug 2016 16:10:40 -0400 Message-ID: <31168.1472069440@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Andrew Gierth writes: > This _looks_ wrong: > set timezone = 'America/Santiago'; > select timestamptz '2016-08-13', timestamptz '2016-08-13' + interval '1 day'; > timestamptz | ?column? > ------------------------+------------------------ > 2016-08-13 00:00:00-04 | 2016-08-14 01:00:00-03 > (1 row) > but I guess it's inevitable, since 2016-08-14 00:00:00 doesn't exist in > the local time, so there's no other possible result to return. Yeah. And after that, the shift persists, eg. # select '2016-08-14 01:00:00-03'::timestamptz + '1 day'::interval; ?column? ------------------------ 2016-08-15 01:00:00-03 (1 row) That's a bit annoying, because it works if you skip over that day: # select '2016-08-13'::timestamptz + '2 days'::interval; ?column? ------------------------ 2016-08-15 00:00:00-03 (1 row) In other words, we could make this scenario "work" if we defined generate_series as base plus N times the increment, rather than as repeated addition of the increment. But I wouldn't be surprised if that would break other corner cases (and it would certainly be slower). Daylight-savings time is not one of the more consistent things in our world ... not that anything at all about the civil calendar is mathematically nice :-(. Certainly, the right answer in this example case is to use the timestamp not timestamptz flavor of generate_series. Or you could use the integer flavor and add the results to a base date using the date + integer operator. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs