pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Glaesemann <grzm@seespotcode.net>
To: Wei Weng <wweng@kencast.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Question on interval
Date: Fri, 20 Apr 2007 14:35:29 -0500
Message-ID: <4AA02EED-0C35-4604-8881-3D3B26C351A9@seespotcode.net> (raw)
In-Reply-To: <46290C34.9080507@kencast.com>
References: <46290C34.9080507@kencast.com>


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





view thread (5+ messages)  latest in thread

Message-ID: <4AA02EED-0C35-4604-8881-3D3B26C351A9@seespotcode.net>
Permalink:  ../4AA02EED-0C35-4604-8881-3D3B26C351A9@seespotcode.net/
Also on:    postgresql.org/message-id/4AA02EED-0C35-4604-8881-3D3B26C351A9@seespotcode.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: grzm@seespotcode.net, wweng@kencast.com
  Subject: Re: Question on interval
  In-Reply-To: <4AA02EED-0C35-4604-8881-3D3B26C351A9@seespotcode.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox