convert interval info into days

From: "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: convert interval info into days
Date: 2003-08-22 17:00:57
Message-ID: 73309C2FDD95D11192E60008C7B1D5BB05FED72F@snt452.corp.bcbsm.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Howdy:

Running PostgreSQL 7.2.1 on RedHat Linux 7.2.

How can I convert data in a table that has been created
with the INTERVAL data type into a numeric format?

Say, I have a table with this type of data:

[snip]
-1 years | 00:00
00:00 | 1 year 90 days
00:00 | 1 year 90 days
00:00 | 1 year 90 days
00:00 | 1 year 90 days
00:00 | 1 year 90 days
00:00 | 1 year 90 days
1 year | 2 years
42 days | 2 years
42 days | 2 years
-1 years | 00:00
-1 years | 00:00
-1 years | 00:00
42 days | 2 years
1 year | 2 years
[/snip]

I want to convert all of this into days, but
I don't think I can use 'to_char' because
I get things like this:

[snip example]
test_db=> select to_char('2 years 3 mons 17 days'::interval, 'YY MM DD');
to_char
----------
02 03 17

--

test_db=> select to_char('2 years'::interval)/365;
ERROR: Function 'to_char(interval)' does not exist
Unable to identify a function that satisfies the given argument
types
You may need to add explicit typecasts
[/snip example]

Any suggestions?

Thanks!

-X

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jan Wieck 2003-08-22 17:19:17 Re: [HACKERS] Buglist
Previous Message btober 2003-08-22 16:56:34 Re: pg_dump and alter database