Re: BUG #3624: EXTRACT(QUARTER FROM INTERVAL) always returns 1

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-bugs(at)postgresql(dot)org, "Eugene M(dot) Hutorny" <eugene(at)ksf(dot)kiev(dot)ua>
Subject: Re: BUG #3624: EXTRACT(QUARTER FROM INTERVAL) always returns 1
Date: 2007-09-21 23:45:13
Message-ID: 28041.1190418313@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Peter Eisentraut <peter_e(at)gmx(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Oded Elharar 2007-09-23 07:57:04 BUG #3626: Cannot install using msi
Previous Message Peter Eisentraut 2007-09-21 18:55:21 Re: BUG #3624: EXTRACT(QUARTER FROM INTERVAL) always returns 1