pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Convert INT to INTERVAL?
5+ messages / 5 participants
[nested] [flat]

* Convert INT to INTERVAL?
@ 2004-02-27 16:54 Brian Knox <laotse@aol.net>
  2004-02-27 17:28 ` Re: Convert INT to INTERVAL? Stephan Szabo <sszabo@megazone.bigpanda.com>
  2004-02-27 17:40 ` Re: Convert INT to INTERVAL? Bruno Wolff III <bruno@wolff.to>
  2004-02-27 18:07 ` Re: Convert INT to INTERVAL? Michael Chaney <mdchaney@michaelchaney.com>
  2004-02-27 18:12 ` Re: Convert INT to INTERVAL? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 4 replies; 5+ messages in thread

From: Brian Knox @ 2004-02-27 16:54 UTC (permalink / raw)
  To: pgsql-sql

Is it possible within pl/pgsql, to convert an integer to an interval in 
months? IE, if num_months is an INT set to 48, can it be converted to an 
interval?

Thanks,
Brian



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

* Re: Convert INT to INTERVAL?
  2004-02-27 16:54 Convert INT to INTERVAL? Brian Knox <laotse@aol.net>
@ 2004-02-27 17:28 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Stephan Szabo @ 2004-02-27 17:28 UTC (permalink / raw)
  To: Brian Knox <laotse@aol.net>; +Cc: pgsql-sql

On Fri, 27 Feb 2004, Brian Knox wrote:

> Is it possible within pl/pgsql, to convert an integer to an interval in
> months? IE, if num_months is an INT set to 48, can it be converted to an
> interval?

You should be able to say something like
 num_months * INTERVAL '1 month'
I believe.



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

* Re: Convert INT to INTERVAL?
  2004-02-27 16:54 Convert INT to INTERVAL? Brian Knox <laotse@aol.net>
@ 2004-02-27 17:40 ` Bruno Wolff III <bruno@wolff.to>
  3 siblings, 0 replies; 5+ messages in thread

From: Bruno Wolff III @ 2004-02-27 17:40 UTC (permalink / raw)
  To: Brian Knox <laotse@aol.net>; +Cc: pgsql-sql

On Fri, Feb 27, 2004 at 11:54:04 -0500,
  Brian Knox <laotse@aol.net> wrote:
> Is it possible within pl/pgsql, to convert an integer to an interval in 
> months? IE, if num_months is an INT set to 48, can it be converted to an 
> interval?

Can you use num_months * '1 month'::interval ?



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

* Re: Convert INT to INTERVAL?
  2004-02-27 16:54 Convert INT to INTERVAL? Brian Knox <laotse@aol.net>
@ 2004-02-27 18:07 ` Michael Chaney <mdchaney@michaelchaney.com>
  3 siblings, 0 replies; 5+ messages in thread

From: Michael Chaney @ 2004-02-27 18:07 UTC (permalink / raw)
  To: pgsql-sql

On Fri, Feb 27, 2004 at 11:54:04AM -0500, Brian Knox wrote:
> Is it possible within pl/pgsql, to convert an integer to an interval in 
> months? IE, if num_months is an INT set to 48, can it be converted to an 
> interval?

select (1||' months')::interval;

You should be able to replace the "1" with your integer variable.

Michael
-- 
Michael Darrin Chaney
mdchaney@michaelchaney.com
http://www.michaelchaney.com/



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

* Re: Convert INT to INTERVAL?
  2004-02-27 16:54 Convert INT to INTERVAL? Brian Knox <laotse@aol.net>
@ 2004-02-27 18:12 ` Tom Lane <tgl@sss.pgh.pa.us>
  3 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2004-02-27 18:12 UTC (permalink / raw)
  To: Brian Knox <laotse@aol.net>; +Cc: pgsql-sql

Brian Knox <laotse@aol.net> writes:
> Is it possible within pl/pgsql, to convert an integer to an interval in 
> months? IE, if num_months is an INT set to 48, can it be converted to an 
> interval?

Sure, just multiply by the appropriate interval value:

regression=# select 48 * '1 month'::interval;
 ?column?
----------
 4 years
(1 row)

			regards, tom lane



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


end of thread, other threads:[~2004-02-27 18:12 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-02-27 16:54 Convert INT to INTERVAL? Brian Knox <laotse@aol.net>
2004-02-27 17:28 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2004-02-27 17:40 ` Bruno Wolff III <bruno@wolff.to>
2004-02-27 18:07 ` Michael Chaney <mdchaney@michaelchaney.com>
2004-02-27 18:12 ` Tom Lane <tgl@sss.pgh.pa.us>

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