Re: Int to Interval conversion

From: Bill Moran <wmoran(at)potentialtech(dot)com>
To: Howard Cole <howardnews(at)selestial(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Int to Interval conversion
Date: 2010-09-14 13:14:08
Message-ID: 20100914091408.ef97df3b.wmoran@potentialtech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In response to Howard Cole <howardnews(at)selestial(dot)com>:
>
> I have a table with a duration field, stored as an Integer. How can I
> retrieve this from the table as an Interval type?
>
> E.g.
>
> create table test (test_id serial primary key, time_in_minutes int);
> insert into test values (1440);
>
> Now how do I extract that as 24:00:00::interval in a query?

SELECT CAST(time_in_minutes || ' minutes' AS INTERVAL) FROM test;

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Szymon Guz 2010-09-14 13:25:31 Re: Int to Interval conversion
Previous Message Matthieu HUIN 2010-09-14 12:59:11 Re: What filesystem to use for postgres?