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-07-08 17:03:28
Message-ID: 1079670.1720458208@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

I took another look at this issue and got annoyed by the fact that the
proposed coding for "quarter" still doesn't satisfy the rule that
the output for a negative interval should be the negative of the
output for the sign-reversed interval. Specifically, if the month
field is zero, the v2 patch always emits 1:

regression=# select extract(quarter from interval '1 day');
extract
---------
1
(1 row)

regression=# select extract(quarter from interval '-1 day');
extract
---------
1
(1 row)

We could fix that by examining the sign of the lower-order fields
when month is zero, as in the v3 patch attached. However, I'm not
at all sure this is really better than v2. Notably, it makes the
documentation's statement that the result is "the month field
divided by 3 plus 1" even more incomplete. I still don't really
want to go into details about the behavior for negative intervals.
OTOH if we did do that, I'd rather write a blanket statement
about the result being the negative of the result for a positive
interval.

Thoughts?

regards, tom lane

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Melanie Plageman 2024-07-08 21:23:52 Re: relfrozenxid may disagree with row XIDs after 1ccc1e05ae
Previous Message Haifang Wang (Centific Technologies Inc) 2024-07-08 15:52:40 RE: [EXTERNAL] Re: Windows Application Issues | PostgreSQL | REF # 51961374

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-07-08 17:08:25 Re: Detoasting optionally to make Explain-Analyze less misleading
Previous Message David E. Wheeler 2024-07-08 16:54:48 Re: ❓ JSON Path Dot Precedence