Re: Date Interval

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Magdalena Komorowska <meluzyna(at)w3(dot)net(dot)pl>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Date Interval
Date: 2005-12-06 16:54:05
Message-ID: 200512061654.jB6Gs5d14178@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Magdalena Komorowska wrote:
> Hi,
> I hale a problem with counting interwal and I can't find what to do with
> this.
> I have two fields in the table:
> Column | Type | Modifiers
> -----------------+---------+-----------
> date_in | date |
> interwal_months | numeric |
> -----------------+---------+-----------
>
> Query
> SELECT date_in + INTERVAL '3 MONTH' FROM any_table
> works fine of course.
>
> However, how to do something like that?
> SELECT date_in + INTERVAL ' interwal_months MONTH' FROM any_table

How about this?

test=> CREATE TABLE test(x TEXT);
CREATE TABLE
test=> INSERT INTO test VALUES ('3');
INSERT 0 1
test=> SELECT current_timestamp + cast(x || ' months' AS INTERVAL) FROM
test;
?column?
-------------------------------
2006-03-06 11:53:05.574279-05
(1 row)

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2005-12-06 17:09:02 Re: Date Interval
Previous Message Luca Pireddu 2005-12-06 16:34:59 Re: lost in system tables