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

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, 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, 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-08-16 16:15:58
Message-ID: Zr97Pqkx9J_BbZHt@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Fri, Aug 16, 2024 at 12:06:35PM -0400, Tom Lane wrote:
> regression=# select n, extract(quarter from interval '1 mon' * n) from generate_series(-12,12) n;
> n | extract
> -----+---------
> -12 | 1
> -11 | -2
> -10 | -2
> -9 | -2

Wow, that "1" is weird to see.

> which is fine on the positive side but it's hard to describe the
> results for negative months as anything but wacko. The v2 patch
> gives
>
> regression=# select n, extract(quarter from interval '1 mon' * n) from generate_series(-12,12) n;
> n | extract
> -----+---------
> -12 | -1
> -11 | -4
> -10 | -4
> -9 | -4
> -8 | -3
> -7 | -3
> -6 | -3
> -5 | -2
> -4 | -2
> -3 | -2
> -2 | -1
> -1 | -1
> 0 | 1
> 1 | 1
> 2 | 1
> 3 | 2
> 4 | 2
> 5 | 2
> 6 | 3
> 7 | 3
> 8 | 3
> 9 | 4
> 10 | 4
> 11 | 4
> 12 | 1
> (25 rows)
>
> which is a whole lot saner. So let's run with v2.

Yes, that v2 output looks very clean. I had to really dig my head into
this so I am not surprised it was confusing to find the right solution.

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

Only you can decide what is important to you.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2024-08-16 17:54:31 Re: REINDEX INDEX pg_catalog.pg_default_acl_role_nsp_obj_index stuck waiting for transaction from the future in PG 13.16
Previous Message Tom Lane 2024-08-16 16:06:35 Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2024-08-16 16:52:16 Re: Remove dependence on integer wrapping
Previous Message Tom Lane 2024-08-16 16:06:35 Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);