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 20210730195505.GE9600@momjian.us
Whole thread Raw
In response to Re: Have I found an interval arithmetic bug?  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On Fri, Jul 30, 2021 at 03:47:53PM -0400, Robert Haas wrote:
> On Fri, Jul 30, 2021 at 3:20 PM Bruce Momjian <bruce@momjian.us> wrote:
> > Uh, what do you suggest then?  You wanted the years/months fixed, and
> > rounding at spill stop time makes sense, and fixes the problem.
> 
> Hmm, maybe I misunderstood. Are you saying that you think the patch
> will fix cases like interval '-1.7 years 29.4 months' and interval
> '29.4 months -1.7 years' to produce the same answer without changing
> any other cases? I had the impression that you were proposing a bigger

Yes, tests from the oringal email:

    SELECT interval '-1.7 years 29.4 months';
        interval
    ----------------
     9 mons 12 days
    (1 row)
    
    SELECT interval '29.4 months -1.7 years';
        interval
    ----------------
     9 mons 12 days
    (1 row)
    
    SELECT interval '-1.7 years' + interval '29.4 months';
        ?column?
    ----------------
     9 mons 12 days
    (1 row)
    
    SELECT interval '29.4 months' + interval '-1.7 years';
        ?column?
    ----------------
     9 mons 12 days

> change to the rules for converting fractional units to units of lower
> type, particularly because Tom called it an "API change".

The API change is to _round_ units greater than months to integeral
month values;  we currently truncate.  Changing the spill behavior has
been rejected.

> For some reason I can't apply the patch locally.
> 
> [rhaas pgsql]$ patch -p1 < ~/Downloads/interval.diff
> (Stripping trailing CRs from patch.)
> patching file doc/src/sgml/datatype.sgml
> (Stripping trailing CRs from patch.)
> patching file src/backend/utils/adt/datetime.c
> patch: **** malformed patch at line 90: @@ -3601,7 +3597,7 @@
> DecodeISO8601Interval(char *str,

Uh, here is the patch again, in case that helps.

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

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


Attachment

pgsql-hackers by date:

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