Int to Interval conversion

Started by Howard Coleover 15 years ago5 messagesgeneral
Jump to latest
#1Howard Cole
howardnews@selestial.com

Hi everyone,

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?

Thanks.

Howard Cole.

#2Bill Moran
wmoran@potentialtech.com
In reply to: Howard Cole (#1)
Re: Int to Interval conversion

In response to Howard Cole <howardnews@selestial.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/

#3Szymon Guz
mabewlun@gmail.com
In reply to: Howard Cole (#1)
Re: Int to Interval conversion

On 14 September 2010 13:57, Howard Cole <howardnews@selestial.com> wrote:

Hi everyone,

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?

<http://www.postgresql.org/mailpref/pgsql-general&gt;

select 1440 * interval '1 minute';

regards
Szymon Guz

#4Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Howard Cole (#1)
Re: Int to Interval conversion

On Tuesday 14 September 2010 4:57:46 am Howard Cole wrote:

Hi everyone,

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?

Thanks.

Howard Cole.

test=> SELECT 1440 * interval '1 min';
?column?
----------
24:00:00
(1 row)

--
Adrian Klaver
adrian.klaver@gmail.com

#5Michael Glaesemann
grzm@seespotcode.net
In reply to: Howard Cole (#1)
Re: Int to Interval conversion

On Sep 14, 2010, at 7:57 , Howard Cole wrote:

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?

test=# SELECT 1440 * INTERVAL '1 minute';
?column?
----------
24:00:00
(1 row)

Michael Glaesemann
grzm seespotcode net