Re: SOLVED - months, intervals and integers

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: SOLVED - months, intervals and integers
Date: 2008-06-04 10:06:02
Message-ID: 200806041106.02724.gary.stainburn@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

This turned out to be much simpler than I thought.

create view crm_script_details as
select *,
(CURRENT_DATE-(cs_age_max::text || 'months')::interval)::date as
start_date,
(CURRENT_DATE-(cs_age_min::text || 'months')::interval)::date as end_date
from crm_scripts;

On Wednesday 04 June 2008 09:44, Gary Stainburn wrote:
> Hi folks
>
> I've got the following table and view and I don't know exactly how to get
> what I want.
>
> The table contains integers for the number of months.
> I want the view to convert those month integers to intervals that it can
> add/subtract from a date.
>
> create table crm_scripts (
> cs_id int4 primary key,
> cs_title varchar(100),
> cs_age_min int4,
> cs_age_max int4,
> cs_script text);
>
> create view crm_script_details as
> select *,
> CURRENT_DATE-cs_age_max as start_date,
> CURRENT_DATE-cs_age_min as end_date,
> from crm_scripts;
>
> If cs_age_min is 6 I need start_date to be CURRENT_DATE-'6
> months'::interval
>
> Any ideas?
> --
> Gary Stainburn
>
> This email does not contain private or confidential material as it
> may be snooped on by interested government parties for unknown
> and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

--
Gary Stainburn

This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Holm Tiffe 2008-06-04 10:47:41 Problems with a Query between 7.3 and 8.2
Previous Message Gary Stainburn 2008-06-04 08:44:41 months, intervals and integers