Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Francisco Olarte <folarte(at)peoplecall(dot)com>, Michael Bondarenko <work(dot)michael(dot)2956(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org, dgrowleyml(at)gmail(dot)com, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Subject: Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
Date: 2024-05-07 21:27:08
Message-ID: 166456.1715117228@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

jian he <jian(dot)universality(at)gmail(dot)com> writes:
> On Wed, Feb 21, 2024 at 4:56 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> Yeah, I see what you mean: the output for negative month counts is
>>> very bizarre, whereas other fields seem to all produce the negative
>>> of what they'd produce for the absolute value of the interval.
>>> We could either try to fix that or decide that rejecting "quarter"
>>> for intervals is the saner answer.

>> After fooling with these cases for a little I'm inclined to think
>> we should do it as attached (no test or docs changes yet).

> ... I don't know how to write the documentation for the `quarter` when
> it's negative.

After poking at it some more, I realized that my draft patch was still
wrong about that. We really have to look at interval->month if we
want to behave plausibly for negative months.

Here's a more fleshed-out patch. I don't think we really need to
document the behavior for negative intervals; at least, we haven't
done that so far for any other fields. I did add testing of such
cases though.

regards, tom lane

Attachment Content-Type Size
v2-interval-week-and-quarter-fixes.patch text/x-diff 13.5 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Wetmore, Matthew (CTR) 2024-05-07 22:09:34 BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
Previous Message Tom Lane 2024-05-07 13:58:15 Re: BUG #18457: Possible data loss needs to be evaluated

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2024-05-07 22:00:23 Re: Weird test mixup
Previous Message Nathan Bossart 2024-05-07 21:17:02 Re: New GUC autovacuum_max_threshold ?