Re: Date Math

Lists: pgsql-general
From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Date Math
Date: 2007-05-07 16:43:50
Message-ID: Pine.LNX.4.64.0705070931310.20021@salmo.appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

I've read both Section 8.5 of the on-line 8.2.4 docs, and the pertinent
sections of Douglas & Douglas, and I'm still not certain that I'm correctly
expressing the query I want. Please correct as needed.

From table (Permits) I want to identify those which expire within a
specified time from today. For example:

SELECT permit_nbr, title, date_issued, term,
process_time from Permits
WHERE (date_issued + term YEARS)
< (CURRENT_DATE + process_time MONTHS);

Should I use TODAY rather than CURRENT_DATE? Do I need to cast intervals
explicitly from seconds to days, months, or years?

Rich

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863


From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Date Math
Date: 2007-05-07 17:02:13
Message-ID: 20070507170213.GA8281@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

am Mon, dem 07.05.2007, um 9:43:50 -0700 mailte Rich Shepard folgendes:
> From table (Permits) I want to identify those which expire within a
> specified time from today. For example:
>
> SELECT permit_nbr, title, date_issued, term,
> process_time from Permits
> WHERE (date_issued + term YEARS)
> < (CURRENT_DATE + process_time MONTHS);
>
> Should I use TODAY rather than CURRENT_DATE? Do I need to cast intervals
> explicitly from seconds to days, months, or years?

I'm not sure if I understand you correctly, if not, sorry.
I think, you should cast your intervals, an example:

select current_date + '10 months'::interval;

You syntax above are wrong.

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net


From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Date Math
Date: 2007-05-07 17:23:23
Message-ID: Pine.LNX.4.64.0705071022520.20021@salmo.appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Mon, 7 May 2007, A. Kretschmer wrote:

> I think, you should cast your intervals, an example:
>
> select current_date + '10 months'::interval;

Andreas,

OK. I wasn't clear on this point.

Thanks,

Rich

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863