Re: BUG #3624: EXTRACT(QUARTER FROM INTERVAL) always returns 1 - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #3624: EXTRACT(QUARTER FROM INTERVAL) always returns 1
Date
Msg-id 28041.1190418313@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #3624: EXTRACT(QUARTER FROM INTERVAL) always returns 1  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-bugs
Peter Eisentraut <peter_e@gmx.net> writes:
> SELECT EXTRACT(QUARTER FROM INTERVAL '200 days') gives 1.  Why is that?

Because interval_part does

                case DTK_QUARTER:
                    result = (tm->tm_mon / 3) + 1;
                    break;

Not sure that changing this is a good idea --- note that most of the
other cases also have blinders on about which fields of the struct pg_tm
to look at, and you'd need to make not-very-defensible assumptions about
conversion rates to incorporate other fields.  Possibly the correct
answer is "you should apply justify_interval first, if that's the
behavior you want".

regression=# select justify_interval(INTERVAL '200 days');
 justify_interval
------------------
 6 mons 20 days
(1 row)

regression=# select extract(quarter from justify_interval(INTERVAL '200 days'));
 date_part
-----------
         3
(1 row)

            regards, tom lane

pgsql-bugs by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: BUG #3624: EXTRACT(QUARTER FROM INTERVAL) always returns 1
Next
From: "Oded Elharar"
Date:
Subject: BUG #3626: Cannot install using msi