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



---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

              http://www.postgresql.org/docs/faq

Reply via email to