Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
Bruce Momjian <bruce@momjian.us>
From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: jian he <jian.universality@gmail.com>, 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-08-16T02:45:58Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- extract.sql (application/sql)
- master.out (text/plain)
- patch2.out (text/plain)
- patch3.out (text/plain)
On Mon, Jul 8, 2024 at 01:03:28PM -0400, Tom Lane wrote: > 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? I tested master, patch version 2 and patch version 3 with some sample extract() queires, attached. I like patch version 2. Patch version 3 bothers me because "-600 days" is ignored if months is non-zero, and used for its sign for zero month values, which seems odd to me; better to ignore it. -- Bruce Momjian <bruce@momjian.us> https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you.
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix extraction of week and quarter fields from intervals.
- 6be39d77a70d 18.0 landed
-
Doc: improve explanation of type interval, especially extract().
- fcd210d496da 17.0 landed
- ebf52e9b7532 14.12 landed
- eb1d008a7a18 13.15 landed
- 6d03e8109250 15.7 landed
- 3ad319b8cad4 16.3 landed