Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
Michael Bondarenko <work.michael.2956@gmail.com>
From: Michael Bondarenko <work.michael.2956@gmail.com>
To: jian he <jian.universality@gmail.com>, pgsql-bugs@lists.postgresql.org, dgrowleyml@gmail.com
Date: 2024-02-17T08:00:39Z
Lists: pgsql-bugs, pgsql-hackers
When testing I stumbled upon that too, but I thought no calculation was
happening in the interval field. However, it's different with the days and
months etc. It seems no calculation for day and month and more:
tpch=# select extract(day from interval '86400000 seconds');
extract
---------
0
(1 row)
tpch=# select extract(month from interval '86400000 seconds');
extract
---------
0
(1 row)
tpch=# select extract(year from interval '86400000 seconds');
extract
---------
0
(1 row)
But calculation is present for hour, and minutes and seconds (90061 sec is
1 day 1 hour 1 minute 1 second):
tpch=# select extract(minute from interval '90061 seconds');
extract
---------
1
(1 row)
tpch=# select extract(hour from interval '90061 seconds');
extract
---------
25
(1 row)
tpch=# select extract(second from interval '90061 seconds');
extract
----------
1.000000
(1 row)
The docs mention *The hour field (0–23)* for the hours, which is not true
because it's not the field at all, but the calculated amount, and the value
is not 0-23.
On Sat, Feb 17, 2024 at 3:48 AM jian he <jian.universality@gmail.com> wrote:
> in `9.9.1. EXTRACT, date_part`
> EXTRACT(field FROM source)
>
> I saw more inconsistencies with the doc when `source` is an interval.
>
> the `minute` field
> select extract(minute from interval '2011 year 16 month 35 day 48 hour
> 1005 min 71 sec 11 ms');
> select extract(minute from interval '2011 year 16 month 35 day 48 hour
> 1005 min 2 sec 11 ms');
> select extract(minute from interval '2011 year 16 month 35 day 48 hour
> 1005 min 2 sec 11 ms');
>
> the `hour` field:
> select extract(hour from interval '2011 year 16 month 35 day 48 hour
> 1005 min 71 sec 11 ms');
> select extract(hour from interval '2011 year 16 month 35 day 48 hour
> 1005 min 2 sec 11 ms');
> select extract(hour from interval '2011 year 16 month 35 day 48 hour
> 1005 min 71 sec 11111111111 ms');
>
> the `quarter` field:
> select extract(quarter from interval '2011 year 12 month 48 hour 1005
> min 2 sec 11 ms');
> SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-12-16 20:38:40');
>
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