pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pietro Pugni <pietro.pugni@gmail.com>
To: Marko Tiikkaja <marko@joh.to>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
Date: Thu, 27 Apr 2017 01:48:41 +0200
Message-ID: <6CEF6FC2-6081-48CC-B534-055594B3851A@gmail.com> (raw)
In-Reply-To: <CAL9smLD5ARjoWon=YgJCXKD-Dc9cCPXOhNRQYxu_J-4ivPeuPw@mail.gmail.com>
References: <20170426182322.24371.95224@wrigleys.postgresql.org>
	<CAKFQuwZ+PXKFrQ+LqOOorfva9nMesie0WQpe_hJTdkMn7vCZAw@mail.gmail.com>
	<5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com>
	<CAKFQuwZDo-CwNiqJ_v64HkKntggFmz1sN82n+FLy99qfez9-3g@mail.gmail.com>
	<AA4AA8B1-AD27-458F-9941-6E5B5F56EACA@gmail.com>
	<CAL9smLD5ARjoWon=YgJCXKD-Dc9cCPXOhNRQYxu_J-4ivPeuPw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

> On Thu, Apr 27, 2017 at 1:01 AM, Pietro Pugni <pietro.pugni@gmail.com <mailto: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’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. 
> 
> 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=# select age('2017-01-30'::date, '1912-02-29'::date) + '1912-02-29'::date;
      ?column?       
---------------------
 2017-01-30 00:00:00

(II)
postgres=# 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’s something wrong..



Kind regards
 Pietro Pugni

view thread (25+ messages)  latest in thread

Message-ID: <6CEF6FC2-6081-48CC-B534-055594B3851A@gmail.com>
Permalink:  ../6CEF6FC2-6081-48CC-B534-055594B3851A@gmail.com/
Also on:    postgresql.org/message-id/6CEF6FC2-6081-48CC-B534-055594B3851A@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: pietro.pugni@gmail.com, marko@joh.to, david.g.johnston@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
  In-Reply-To: <6CEF6FC2-6081-48CC-B534-055594B3851A@gmail.com>
  References: <20170426182322.24371.95224@wrigleys.postgresql.org> <CAKFQuwZ+PXKFrQ+LqOOorfva9nMesie0WQpe_hJTdkMn7vCZAw@mail.gmail.com> <5752C491-B0EC-4D1E-AF97-5E1C8C793A8A@gmail.com> <CAKFQuwZDo-CwNiqJ_v64HkKntggFmz1sN82n+FLy99qfez9-3g@mail.gmail.com> <AA4AA8B1-AD27-458F-9941-6E5B5F56EACA@gmail.com> <CAL9smLD5ARjoWon=YgJCXKD-Dc9cCPXOhNRQYxu_J-4ivPeuPw@mail.gmail.com> <6CEF6FC2-6081-48CC-B534-055594B3851A@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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