Re: Question on interval - Mailing list pgsql-sql

From Michael Glaesemann
Subject Re: Question on interval
Date
Msg-id 4AA02EED-0C35-4604-8881-3D3B26C351A9@seespotcode.net
Whole thread Raw
In response to Question on interval  (Wei Weng <wweng@kencast.com>)
List pgsql-sql
On Apr 20, 2007, at 13:53 , Wei Weng wrote:

> How do I write a query that converts an interger to the interval type?
>
> Like convert integer 10 to INTERVAL '10 seconds'?

An easy way to do this is:

SELECT 10 * INTERVAL '1 second';

>
> The integer is a column in a table though, so it is more like  
> convert integer tbl.theInteger to INTERVAL 'tbl.theInteger seconds".

If you'd like to change the type of the column to interval, you can  
use something like

ALTER TABLE a_table
ALTER COLUMN an_integer_column TYPE INTERVAL
USING an_integer_column * INTERVAL '1 second';

You could also create a view that would present the integer column as  
an interval if you don't want to alter the table itself.

Does this help?

Michael Glaesemann
grzm seespotcode net




pgsql-sql by date:

Previous
From: "Rodrigo De León"
Date:
Subject: Re: Question on interval
Next
From: Scott Marlowe
Date:
Subject: Re: Question on interval