Re: [BUGS] BUG #14632: Plus and minus operators inconsistency with leap years and year intervals. - Mailing list pgsql-bugs

From Pietro Pugni
Subject Re: [BUGS] BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
Date
Msg-id 07CA08CB-78FB-42F6-832F-F9F7B838C1A6@gmail.com
Whole thread Raw
In response to Re: [BUGS] BUG #14632: Plus and minus operators inconsistency withleap years and year intervals.  (Pantelis Theodosiou <ypercube@gmail.com>)
Responses Re: [BUGS] BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.
List pgsql-bugs
Il giorno 27 apr 2017, alle ore 14:31, Pantelis Theodosiou <ypercube@gmail.com> ha scritto:

You seem to think that expressions similar to these should yield the same results:

    dateD + intervalA + intervalB

    (dateD + intervalA) + intervalB

    dateD + (intervalA + intervalB)


But they don't and they couldn't, as many others have mentioned already.
Expressions 1 and 2 are equivalent but the 3rd is not.

And we don't even need leap years to find such "wrong" results. We have leap seconds (which are rare) and leap months (which are pretty common although we don't call them leap months). Just try 

SELECT 
   '2017-03-31'::date + '1 month'::interval + '1 month'::interval,
   '2017-03-31'::date + (
'1 month'::interval + '1 month'::interval) ;

Not all months have the same number of days and there is not a way to fix that.

It's just not possible to squeeze 31 days in a 30-days month. What should  '2017-03-31'::date + '1 month'::interval result and what should '2017-03-30'::date + '1 month'::interval result? 

Regards, 
Pantelis

Probably it should be worth it to implement a sort of age2(timestamp, timestamp) function that returns ages accounting for leap years, months, days and seconds, without changing the actual implementation of age(timestamp, timestamp).

Kind regards,
 Pietro Pugni

pgsql-bugs by date:

Previous
From: henry_boehlert@agilent.com
Date:
Subject: [BUGS] BUG #14634: On Windows pg_basebackup should write tar to stdout inbinary mode
Next
From: Pietro Pugni
Date:
Subject: Re: [BUGS] BUG #14632: Plus and minus operators inconsistency with leap years and year intervals.