Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3URv-0001oZ-1x for pgsql-bugs@arkaria.postgresql.org; Wed, 26 Apr 2017 21:26:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d3URu-0004XL-3t for pgsql-bugs@arkaria.postgresql.org; Wed, 26 Apr 2017 21:26:10 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d3URC-00038C-RA for pgsql-bugs@postgresql.org; Wed, 26 Apr 2017 21:25:26 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d3UR6-0005Dv-96 for pgsql-bugs@postgresql.org; Wed, 26 Apr 2017 21:25:25 +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 v3QLPIpJ009067; Wed, 26 Apr 2017 17:25:18 -0400 From: Tom Lane To: Pietro Pugni cc: "David G. Johnston" , "pgsql-bugs@postgresql.org" Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals. In-reply-to: <5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com> References: <20170426182322.24371.95224@wrigleys.postgresql.org> <5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com> Comments: In-reply-to Pietro Pugni message dated "Wed, 26 Apr 2017 22:30:50 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <9065.1493241918.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Wed, 26 Apr 2017 17:25:18 -0400 Message-ID: <9066.1493241918@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 Pietro Pugni writes: > Adding 10 years to 1912-02-29 returns 1922-02-29, as expected. No, it doesn't, and it would be wrong to do so because there is no such date; 1922 wasn't a leap year. There are basically three things the addition operator could do here: throw an error, return 1922-02-28, or return 1922-03-01. The first choice seems rather unhelpful. The second choice is more in keeping with what we do for some other similar cases, such as regression=# select '2017-01-31'::date + '1 month'::interval; ?column? --------------------- 2017-02-28 00:00:00 (1 row) regression=# select '2017-01-31'::date + '3 months'::interval; ?column? --------------------- 2017-04-30 00:00:00 (1 row) Basically the thought is that the last day of the month is more likely to be the answer the user wants for such cases than the first day of the next month. If you want the less-fuzzy semantics of, say, "plus 30 days", you can have that too but you need to say it that way. The really short answer is that civil calendars were not invented by mathematicians and expecting them to obey mathematical laws is doomed to be an exercise in frustration. > The bug basically consists of the vague meaning of “years” applied to > leap years. It should be revised in order to be consistent and correct. As remarked somewhere in our documentation, you'd need to take that up with the Pope, not with us database hackers. We didn't invent the calendar rules. 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