Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);

From: Michael Bondarenko <work(dot)michael(dot)2956(at)gmail(dot)com>
To: work(dot)michael(dot)2956(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
Date: 2024-02-16 12:21:57
Message-ID: CAF_O+z0EjWLt4vVgZeQ8vUC9ggT0hbXWPprv9-aCVhH=QTZ3MQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Adding another inconsistency I found in the docs to this thread (
https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
):

The docs say: "source must be a value expression of type *timestamp*, *time*,
or *interval*. (Expressions of type *date* are *cast to timestamp* and can
therefore be used as well.)"

Which implies that the following two results must be the same:

tpch=# select extract(microseconds from date '1924.01.01');
ERROR: date units "microseconds" not supported

tpch=# select extract(microseconds from (date '1924.01.01')::timestamp);
extract
---------
0
(1 row)

However, the behaviour is different, which suggests that the date is indeed
treated as its own type in EXTRACT, and not cast to timestamp.

On Fri, Feb 16, 2024 at 2:07 PM PG Bug reporting form <
noreply(at)postgresql(dot)org> wrote:

> The following bug has been logged on the website:
>
> Bug reference: 18348
> Logged by: Michael Bondarenko
> Email address: work(dot)michael(dot)2956(at)gmail(dot)com
> PostgreSQL version: 14.10
> Operating system: macOS
> Description:
>
> Hello,
>
> I'm building a random semantically-correct SQL code generator for
> PostgreSQL
> and I stumbled upon an inconsistency:
>
> tpch=# select extract(year from interval '3 years');
> extract
> ---------
> 3
> (1 row)
>
> tpch=# select extract(week from interval '3 weeks');
> ERROR: interval units "week" not supported
>
> In the documentation it's mentioned that 'week' is an ISO 8601 week, so it
> makes sense why it's not applicable to INTERVAL, which is the same for
> isoyear. However, the field is named week and not isoweek, so I expect it
> to
> work like the `select extract(year from interval '3 years');` does.
> Moreover, the documentation does not mention that the field cannot be
> extracted from INTERVAL, like it does for isoyear:
>
> https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
> .
>
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2024-02-16 12:32:31 Re: BUG #18344: Pruning tables partitioned by bool range fails with invalid strategy
Previous Message PG Bug reporting form 2024-02-16 12:06:55 BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2024-02-16 12:37:16 Re: pg_upgrade and logical replication
Previous Message vignesh C 2024-02-16 12:09:47 confirmed flush lsn seems to be move backward in certain error cases