From: | Harald Fuchs <hf0923x(at)protecting(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Date Interval |
Date: | 2005-12-06 17:15:24 |
Message-ID: | 87k6eixi37.fsf@srv.protecting.net |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
In article <200512061654(dot)jB6Gs5d14178(at)candle(dot)pha(dot)pa(dot)us>,
Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> 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)
Since Magdalena doesn't store the number of months in a string, the
following might be more convenient:
SELECT date_in + interwal_months * INTERVAL '1 MONTH' FROM any_table
From | Date | Subject | |
---|---|---|---|
Next Message | Magdalena Komorowska | 2005-12-06 17:46:50 | Re: Date Interval |
Previous Message | Tom Lane | 2005-12-06 17:12:46 | Re: [SQL] lost in system tables |