I have a column defined as type 'INTERVAL'. It always contains values
with an integral number of months. For example:
orca_v0_1=# select duration from budget;
duration
---------------
1 year
7 mons
1 year 5 mons
(3 rows)
Is there a way to query this column such that is only return the
integral number of months? In the example above, I would like to see
12, 7, 17 returned.
I've tried using 'extract', but the resulting query is rather... shall
we say, inelegent:
orca_v0_1=# select extract(YEARS FROM duration)*12 + extract(MONTHS FROM
duration) from budget;
?column?
----------
12
7
17
(3 rows)
PS: Finally, just out of curiousity, is it possible to return the
"fractional" number of months for the situation that an interval is '4
months 2 days'::INTERVAL ?
--
-**-*-*---*-*---*-*---*-----*-*-----*---*-*---*-----*-----*-*-----*---
Jon Lapham
Extracta Moléculas Naturais, Rio de Janeiro, Brasil
email: lapham@extracta.com.br web: http://www.extracta.com.br/
***-*--*----*-------*------------*--------------------*---------------