Re: Question on interval

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Wei Weng <wweng(at)kencast(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Question on interval
Date: 2007-04-20 19:35:29
Message-ID: 4AA02EED-0C35-4604-8881-3D3B26C351A9@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Scott Marlowe 2007-04-20 20:11:06 Re: Question on interval
Previous Message Rodrigo De León 2007-04-20 19:29:05 Re: Question on interval