From: | Jon Lapham <lapham(at)extracta(dot)com(dot)br> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | '1 years'::interval to months? |
Date: | 2001-11-20 12:11:24 |
Message-ID: | 3BFA486C.804@extracta.com.br |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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(at)extracta(dot)com(dot)br web: http://www.extracta.com.br/
***-*--*----*-------*------------*--------------------*---------------
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Pilsl | 2001-11-20 12:22:59 | anyone knows about pam_pgsql ? |
Previous Message | Vince Vielhaber | 2001-11-20 11:52:29 | Re: email time warps |