pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Question on interval
5+ messages / 5 participants
[nested] [flat]

* Question on interval
@ 2007-04-20 18:53 Wei Weng <wweng@kencast.com>
  2007-04-20 19:29 ` Re: Question on interval Rodrigo De León <rdeleonp@gmail.com>
  2007-04-20 19:35 ` Re: Question on interval Michael Glaesemann <grzm@seespotcode.net>
  2007-04-20 20:11 ` Re: Question on interval Scott Marlowe <smarlowe@g2switchworks.com>
  0 siblings, 3 replies; 5+ messages in thread

From: Wei Weng @ 2007-04-20 18:53 UTC (permalink / raw)
  To: pgsql-sql

Hi all.

How do I write a query that converts an interger to the interval type?

Like convert integer 10 to INTERVAL '10 seconds'?

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

Thanks!


Wei




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Question on interval
  2007-04-20 18:53 Question on interval Wei Weng <wweng@kencast.com>
@ 2007-04-20 19:29 ` Rodrigo De León <rdeleonp@gmail.com>
  2007-04-21 00:38   ` Re: Question on interval Steve Crawford <scrawford@pinpointresearch.com>
  2 siblings, 1 reply; 5+ messages in thread

From: Rodrigo De León @ 2007-04-20 19:29 UTC (permalink / raw)
  To: pgsql-sql; +Cc: Wei Weng <wweng@kencast.com>

On 4/20/07, Wei Weng <wweng@kencast.com> wrote:
> Hi all.
>
> How do I write a query that converts an interger to the interval type?
>
> Like convert integer 10 to INTERVAL '10 seconds'?
>
> The integer is a column in a table though, so it is more like convert
> integer tbl.theInteger to INTERVAL 'tbl.theInteger seconds".
>
> Thanks!
>
>
> Wei

select (10||' sec')::interval;



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Question on interval
  2007-04-20 18:53 Question on interval Wei Weng <wweng@kencast.com>
  2007-04-20 19:29 ` Re: Question on interval Rodrigo De León <rdeleonp@gmail.com>
@ 2007-04-21 00:38   ` Steve Crawford <scrawford@pinpointresearch.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Steve Crawford @ 2007-04-21 00:38 UTC (permalink / raw)
  To: Rodrigo De León <rdeleonp@gmail.com>; +Cc: pgsql-sql@postgresql.org, Wei Weng <wweng@kencast.com>

Rodrigo De León wrote:
> On 4/20/07, Wei Weng <wweng@kencast.com> wrote:
>> Hi all.
>>
>> How do I write a query that converts an interger to the interval type?
>>
>> Like convert integer 10 to INTERVAL '10 seconds'?
>>
>> The integer is a column in a table though, so it is more like convert
>> integer tbl.theInteger to INTERVAL 'tbl.theInteger seconds".
>>
>> Thanks!
>>
>>
>> Wei
> 
> select (10||' sec')::interval;

Or, if you prefer:
select 10*'1 second'::interval;

Cheers,
Steve




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Question on interval
  2007-04-20 18:53 Question on interval Wei Weng <wweng@kencast.com>
@ 2007-04-20 19:35 ` Michael Glaesemann <grzm@seespotcode.net>
  2 siblings, 0 replies; 5+ messages in thread

From: Michael Glaesemann @ 2007-04-20 19:35 UTC (permalink / raw)
  To: Wei Weng <wweng@kencast.com>; +Cc: 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





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Question on interval
  2007-04-20 18:53 Question on interval Wei Weng <wweng@kencast.com>
@ 2007-04-20 20:11 ` Scott Marlowe <smarlowe@g2switchworks.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Scott Marlowe @ 2007-04-20 20:11 UTC (permalink / raw)
  To: Wei Weng <wweng@kencast.com>; +Cc: pgsql-sql

On Fri, 2007-04-20 at 13:53, Wei Weng wrote:
> Hi all.
> 
> How do I write a query that converts an interger to the interval type?
> 
> Like convert integer 10 to INTERVAL '10 seconds'?
> 
> The integer is a column in a table though, so it is more like convert 
> integer tbl.theInteger to INTERVAL 'tbl.theInteger seconds".

A lot of the times, it's easiest to multiply it:

select ..... where somedatefield > now() - interval '1 minute' * 5



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2007-04-21 00:38 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-04-20 18:53 Question on interval Wei Weng <wweng@kencast.com>
2007-04-20 19:29 ` Rodrigo De León <rdeleonp@gmail.com>
2007-04-21 00:38   ` Steve Crawford <scrawford@pinpointresearch.com>
2007-04-20 19:35 ` Michael Glaesemann <grzm@seespotcode.net>
2007-04-20 20:11 ` Scott Marlowe <smarlowe@g2switchworks.com>

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