pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: jian he <jian.universality@gmail.com>
Cc: Francisco Olarte <folarte@peoplecall.com>
Cc: Michael Bondarenko <work.michael.2956@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org, dgrowleyml@gmail.com, Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Subject: Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
Date: Fri, 16 Aug 2024 11:26:58 -0400
Message-ID: <Zr9vwnzROmfi_MI4@momjian.us> (raw)
In-Reply-To: <Zr69ZnXWlS_2_bvI@momjian.us>
References: <3749306.1708222748@sss.pgh.pa.us>
	<CACJufxHL0g73FPaRS+OGSYWJ0YbP6nEdVK79=wjL-TKU0_heDw@mail.gmail.com>
	<222870.1708458150@sss.pgh.pa.us>
	<270582.1708462564@sss.pgh.pa.us>
	<CACJufxFOjGpAQJ5EJ0=a1geERgdHW77SEdRyK8A_qwB3CVdwhQ@mail.gmail.com>
	<166456.1715117228@sss.pgh.pa.us>
	<CACJufxGFuZsj+31a204fFpxv_RCHA-u1h6WEBZ6qpjBVoio5dQ@mail.gmail.com>
	<476283.1715177448@sss.pgh.pa.us>
	<1079670.1720458208@sss.pgh.pa.us>
	<Zr69ZnXWlS_2_bvI@momjian.us>

On Thu, Aug 15, 2024 at 10:45:58PM -0400, Bruce Momjian wrote:
> > We could fix that by examining the sign of the lower-order fields
> > when month is zero, as in the v3 patch attached.  However, I'm not
> > at all sure this is really better than v2.  Notably, it makes the
> > documentation's statement that the result is "the month field
> > divided by 3 plus 1" even more incomplete.  I still don't really
> > want to go into details about the behavior for negative intervals.
> > OTOH if we did do that, I'd rather write a blanket statement
> > about the result being the negative of the result for a positive
> > interval.
> > 
> > Thoughts?
> 
> I tested master, patch version 2 and patch version 3 with some sample
> extract() queires, attached.  I like patch version 2.  Patch version 3
> bothers me because "-600 days" is ignored if months is non-zero, and
> used for its sign for zero month values, which seems odd to me;  better
> to ignore it.

I think there are two more issues.  In patch version 3, when months is
zero and you check days, you should also check seconds if days is zero.

I think the other issue is that zero months is a valid Q1 value, since
months 0-2 are Q1;  from master:

	SELECT extract(quarter FROM interval '0 months');
	 extract
	---------
	       1
	
	SELECT extract(quarter FROM interval '2 months');
	 extract
	---------
	       1
	
	SELECT extract(quarter FROM interval '3 months');
	 extract
	---------
	       2

so the idea that we should adjust the sign for zero months quarter
extract doesn't seem logical to me.

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Only you can decide what is important to you.





view thread (31+ messages)  latest in thread

Message-ID: <Zr9vwnzROmfi_MI4@momjian.us>
Permalink:  ../Zr9vwnzROmfi_MI4@momjian.us/
Also on:    postgresql.org/message-id/Zr9vwnzROmfi_MI4@momjian.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: bruce@momjian.us, tgl@sss.pgh.pa.us, jian.universality@gmail.com, folarte@peoplecall.com, work.michael.2956@gmail.com, peter.eisentraut@enterprisedb.com
  Subject: Re: BUG #18348: Inconsistency with EXTRACT([field] from INTERVAL);
  In-Reply-To: <Zr9vwnzROmfi_MI4@momjian.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox