Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3Wgj-0008SX-O4 for pgsql-bugs@arkaria.postgresql.org; Wed, 26 Apr 2017 23:49:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d3Wgi-0002wm-Ia for pgsql-bugs@arkaria.postgresql.org; Wed, 26 Apr 2017 23:49:36 +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 1d3Wg1-0001kE-AJ for pgsql-bugs@postgresql.org; Wed, 26 Apr 2017 23:48:53 +0000 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1d3Wfy-0008DG-02 for pgsql-bugs@postgresql.org; Wed, 26 Apr 2017 23:48:51 +0000 Received: by mail-wr0-x22c.google.com with SMTP id z52so8142999wrc.2 for ; Wed, 26 Apr 2017 16:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc:message-id:references :to; bh=Qr90IOD1BRgWQj50kShVqdLQn8d7BWOf5fQwdyLYICc=; b=BOvRyWsQXbeb+emqJgY5VU12MM9oY/WRmFJwq4bgfwOi1D8Vlj06eTVqtzqyYszcvV xntXe1QOG3ri/z4KzB2I5M83riM/e2DJCviIGZxU+VSaIAuB+hHElWiEUL6Ng/LLPYpx FGI+DTVsH4wYev2Tnkm6S8LhvQa/69zLYo1D4/ReKjAiuwGEKTcE4GVLAnCg2MF3VA5r IjXcMufTHhLfVBYmQgcAWwR2QEWNs1us0ny5VvXkJZk1hsMYRqatYjzq2N6zV19AZfuu vERgzPbO+Xpnud2wpm/vM47NMntvcuBA5xF7cM+wyOHP56EAO9IuIK+OLhtWKUgXONPq Q/NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=Qr90IOD1BRgWQj50kShVqdLQn8d7BWOf5fQwdyLYICc=; b=DnwCeXBEmkFbNGKC2K0t2y3BGvPUOHKSUv1xp4aF9CDKs7KPK3Z/L4Siaw/QaR6KoD S7LGs0TScg+gPz89eV1bNMDJtvewWlr93jptFS1smyP12nTSHQau7wepRfmzg3SUbTSX jWO0Bb28yKWLe49Z3X5D9hGaJTlpTUBC/miC0mrjertj3+us7S6vw4ykZbEXv3DHnfqd KmQYCK86R0UcR1MCZZVJDcIcmfaA5cCs1FCWHPs0tRmf325iezvsABS6oMQIoTJuXzi0 aEY6yw7Z4nRrViDKO5JV/QeBlDv1rFDOqAdTO5HD085XX/xj6s4Yo2oQEd1848dtM294 YS+Q== X-Gm-Message-State: AN3rC/5C6apDuaRfxznHgD/Zd9Vw/2apwr0ACyQWRFqCj++RW/YlQX+q K2KYIhxv2AoXrg== X-Received: by 10.223.139.87 with SMTP id v23mr1487135wra.9.1493250528060; Wed, 26 Apr 2017 16:48:48 -0700 (PDT) Received: from [192.168.2.5] (2-230-140-245.ip202.fastwebnet.it. [2.230.140.245]) by smtp.gmail.com with ESMTPSA id 133sm1143862wms.22.2017.04.26.16.48.46 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Apr 2017 16:48:46 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_E57C494E-EAE1-4B20-94C7-DB42C21B8A68" Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals. From: Pietro Pugni In-Reply-To: Date: Thu, 27 Apr 2017 01:48:41 +0200 Cc: "David G. Johnston" , "pgsql-bugs@postgresql.org" , Tom Lane Message-Id: <6CEF6FC2-6081-48CC-B534-055594B3851A@gmail.com> References: <20170426182322.24371.95224@wrigleys.postgresql.org> <5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com> To: Marko Tiikkaja X-Mailer: Apple Mail (2.3124) X-Pg-Spam-Score: -2.0 (--) 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 --Apple-Mail=_E57C494E-EAE1-4B20-94C7-DB42C21B8A68 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Thu, Apr 27, 2017 at 1:01 AM, Pietro Pugni > wrote: >> Expect 1912-02-28 is a correct response. The only reason you think = the 29th comes into play here is because you remember that the starting = point was the 29th. The system has no such memory. >=20 > And this is logically wrong because it leads to wrong results. I=E2=80=99= m aware that time intervals are difficult to manage but more exactness = is needed here: '10 years' must have the same meaning when added to a = date and subtracted from it, otherwise it leads to wrong results.=20 >=20 > Your suggestion just moves the wrong results to another use case; see = my response upthread. There is no objectively correct answer here, like = you seem to think. I just found this query clearly shows the underlying algorithm is = somewhat wrong: (I) postgres=3D# select age('2017-01-30'::date, '1912-02-29'::date) + = '1912-02-29'::date; ?column? =20 --------------------- 2017-01-30 00:00:00 (II) postgres=3D# select age('2017-02-01'::date, '1912-02-29'::date) + = '1912-02-29'::date; ?column? =20 --------------------- 2017-01-30 00:00:00 Query (II) should return 2017-02-01 instead of 2017-01-30 and the two = queries should return different results. More generally, if we calculate the previous query on all the dates of = February: select age('2017-01-31'::date, '1912-02-29'::date) + '1912-02-29'::date; select age('2017-02-01'::date, '1912-02-29'::date) + '1912-02-29'::date; select age('2017-02-02'::date, '1912-02-29'::date) + '1912-02-29'::date; select age('2017-02-03'::date, '1912-02-29'::date) + '1912-02-29'::date; ... select age('2017-02-28'::date, '1912-02-29'::date) + '1912-02-29'::date; select age('2017-03-01'::date, '1912-02-29'::date) + '1912-02-29'::date; they return, respectively: 2017-01-31 00:00:00 2017-01-30 00:00:00 2017-01-31 00:00:00 2017-02-01 00:00:00 ... 2017-02-26 00:00:00 2017-03-01 00:00:00 while the expected results are: 2017-01-31 00:00:00 2017-02-01 00:00:00 2017-02-02 00:00:00 2017-02-03 00:00:00 ... 2017-02-28 00:00:00 2017-03-01 00:00:00 I understand why this happens (this has been discussed previously) but = clearly there=E2=80=99s something wrong.. Kind regards Pietro Pugni --Apple-Mail=_E57C494E-EAE1-4B20-94C7-DB42C21B8A68 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On Thu, Apr 27, = 2017 at 1:01 AM, Pietro Pugni <pietro.pugni@gmail.com> wrote:
Expect = 1912-02-28 is a correct response.  The only reason you think the = 29th comes into play here is because you remember that the starting = point was the 29th.  The system has no such = memory.
And this is logically = wrong because it leads to wrong results. I=E2=80=99m aware that time = intervals are difficult to manage but more exactness is needed here: '10 = years' must have the same meaning when added to a date and subtracted = from it, otherwise it leads to wrong = results. 

Your suggestion just moves the wrong = results to another use case; see my response upthread.  There is no = objectively correct answer here, like you seem to think.


I just = found this query clearly shows the underlying algorithm is somewhat = wrong:

(I)
postgres=3D# select age('2017-01-30'::date, = '1912-02-29'::date) + '1912-02-29'::date;
      = ?column?       
---------------------
 2017-01-30 00:00:00

(II)
postgres=3D# select age('2017-02-01'::date, '1912-02-29'::date) + = '1912-02-29'::date;
      ?column?     =   
---------------------
 2017-01-30 = 00:00:00


Query (II) should = return 2017-02-01 instead of 2017-01-30 and the two queries should = return different results.
More generally, if we = calculate the previous query on all the dates of February:

select age('2017-01-31'::date, '1912-02-29'::date) + = '1912-02-29'::date;
select age('2017-02-01'::date, '1912-02-29'::date) + = '1912-02-29'::date;
select age('2017-02-02'::date, '1912-02-29'::date) + = '1912-02-29'::date;
select age('2017-02-03'::date, '1912-02-29'::date) + = '1912-02-29'::date;
...
select age('2017-02-28'::date, '1912-02-29'::date) + = '1912-02-29'::date;
select age('2017-03-01'::date, '1912-02-29'::date) + = '1912-02-29'::date;

they return, respectively:
2017-01-31 00:00:00
2017-01-30 00:00:00
2017-01-31 00:00:00
2017-02-01 00:00:00
...
2017-02-26 00:00:00
2017-03-01 00:00:00

while the expected results = are:
2017-01-31 00:00:00
2017-02-01 00:00:00
2017-02-02 00:00:00
2017-02-03 00:00:00
...
2017-02-28 00:00:00
2017-03-01 00:00:00


I understand why this happens (this has been discussed = previously) but clearly there=E2=80=99s something wrong..



Kind regards
 Pietro Pugni



= --Apple-Mail=_E57C494E-EAE1-4B20-94C7-DB42C21B8A68--