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 19:42:30
Message-ID: 222870.1708458150@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 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.

I went ahead and pushed the docs changes after adding more explicit
descriptions of interval's behavior for the field types where it
seemed important. If we make any changes to the behavior for
week or quarter fields, ISTM that should be a HEAD-only change.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2024-02-20 20:56:04 Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
Previous Message Tom Lane 2024-02-20 18:49:07 Re: error "can only drop stats once" brings down database

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2024-02-20 19:42:47 Re: Running the fdw test from the terminal crashes into the core-dump
Previous Message Pavel Stehule 2024-02-20 19:29:29 Re: Schema variables - new implementation for Postgres 15