Fix extraction of week and quarter fields from intervals.
Tom Lane <tgl@sss.pgh.pa.us>
Fix extraction of week and quarter fields from intervals. "EXTRACT(WEEK FROM interval_value)" formerly threw an error. Define it as "tm->tm_mday / 7". (With C99 division semantics, this gives consistent results for negative intervals.) "EXTRACT(QUARTER FROM interval_value)" has been implemented all along, but it formerly gave extremely strange results for negative intervals. Fix it so that the output for -N months is the negative of the output for N months. Per bug #18348 from Michael Bondarenko and subsequent discussion. Discussion: https://postgr.es/m/18348-b097a3587dfde8a4@postgresql.org
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/func.sgml | modified | +12 −1 |
| src/backend/utils/adt/timestamp.c | modified | +17 −1 |
| src/test/regress/expected/interval.out | modified | +47 −14 |
| src/test/regress/sql/interval.sql | modified | +18 −0 |
Documentation touched
Discussion
- BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL); 31 messages · 2024-02-16 → 2024-08-16