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