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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Wetmore, Matthew (CTR)" <Matthew(dot)Wetmore(at)evernorth(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" <pgsql-bugs(at)lists(dot)postgresql(dot)org>, "dgrowleyml(at)gmail(dot)com" <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-05-08 13:55:50
Message-ID: 473944.1715176550@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

"Wetmore, Matthew (CTR)" <Matthew(dot)Wetmore(at)evernorth(dot)com> writes:
> Devils advocating here, feel free to ignore.
> Is there a real need for a negative month? Sounds like high level this could be disastrous if I screw up the syntax. (Ah, memories of DD)

What are you objecting to the "need for"? That intervals can store
negative months at all? I think that ship sailed a couple decades
ago. It's hard to use interval as the output of, say,
timestamp minus timestamp if it refuses to allow negative values.

The next fallback position perhaps could be that extract(quarter ...)
could throw error for negative input, but that seems like mostly a
foot-gun. We've striven elsewhere to not have it throw error, even
if there's not any very sane choice to make. For instance, these
are pre-existing behaviors:

regression=# select extract(quarter from interval 'infinity');
extract
---------

(1 row)

regression=# select extract(quarter from interval '-infinity');
extract
---------

(1 row)

Maybe there's a case for returning null for "quarter" for any negative
months value, but that seems inconsistent with other behaviors of
extract(). The pattern I see for finite values is that negating
the input interval negates each output of extract().

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2024-05-08 14:10:48 Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
Previous Message Chris Travers 2024-05-08 08:02:21 pg_rewind fails on Windows where tablespaces are used

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2024-05-08 13:57:50 Re: CREATE DATABASE with filesystem cloning
Previous Message Peter Eisentraut 2024-05-08 13:51:28 Re: SQL:2011 application time