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

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: jian he <jian.universality@gmail.com>
Cc: Francisco Olarte <folarte@peoplecall.com>, Michael Bondarenko <work.michael.2956@gmail.com>, pgsql-bugs@lists.postgresql.org, dgrowleyml@gmail.com, Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Date: 2024-05-07T21:27:08Z
Lists: pgsql-bugs, pgsql-hackers

Attachments

jian he <jian.universality@gmail.com> writes:
> On Wed, Feb 21, 2024 at 4:56 AM Tom Lane <tgl@sss.pgh.pa.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

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix extraction of week and quarter fields from intervals.

  2. Doc: improve explanation of type interval, especially extract().