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-02-20 20:56:04
Message-ID: 270582.1708462564@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

I wrote:
> jian he <jian(dot)universality(at)gmail(dot)com> writes:
>> On Sun, Feb 18, 2024 at 2:14 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> (Parenthetically, one case that perhaps is surprising is
>>> ERROR: unit "week" not supported for type interval
>>> Why not just return the day field divided by 7?)

>> seems pretty simple?

> Hm, maybe, but does this behave desirably for zero or negative days?

>> So in section 9.9.1. EXTRACT, date_part
>> we may need to document extract(quarter from interval) case.
>> intervals can be negative, which will make the issue more complicated.
>> except the "quarter" field , EXTRACT other fields from intervals, the
>> output seems sane.

> 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).

regards, tom lane

Attachment Content-Type Size
interval-week-and-quarter-fixes.patch text/x-diff 668 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Johnson 2024-02-20 22:27:38 Re: BUG #18352: signature could not be verified for pgdg-common
Previous Message Tom Lane 2024-02-20 19:42:30 Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2024-02-20 21:21:30 Re: System username in pg_stat_activity
Previous Message Tom Lane 2024-02-20 19:48:01 Re: Running the fdw test from the terminal crashes into the core-dump