Re: Have I found an interval arithmetic bug? - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Have I found an interval arithmetic bug?
Date
Msg-id 20210403021905.GF29126@momjian.us
Whole thread Raw
In response to Re: Have I found an interval arithmetic bug?  (Zhihong Yu <zyu@yugabyte.com>)
List pgsql-hackers
On Fri, Apr  2, 2021 at 06:11:08PM -0700, Zhihong Yu wrote:
> Hi,
> I got a local build with second patch where:
> 
> yugabyte=# SELECT  interval '0.3 years' + interval '0.4 years' -
>                 interval '0.7 years';
>  ?column?
> ----------
>  1 mon
> 
> I think the outcome is a bit unintuitive (I would expect result close to 0).

Uh, the current code returns:

    SELECT  interval '0.3 years' + interval '0.4 years' - interval '0.7 years';
     ?column?
    ----------
     -1 mon

and with the patch it is:
    
    SELECT  interval '0.3 years' + interval '0.4 years' - interval '0.7 years';
     ?column?
    ----------
     1 mon

What it isn't, is zero months, which is the obviously ideal answer.


-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  If only the physical world exists, free will is an illusion.




pgsql-hackers by date:

Previous
From: Zhihong Yu
Date:
Subject: Re: Have I found an interval arithmetic bug?
Next
From: Bruce Momjian
Date:
Subject: Re: Have I found an interval arithmetic bug?