Re: Date Math

From: Adrian Klaver <aklaver(at)comcast(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org, Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Subject: Re: Date Math
Date: 2007-05-07 19:05:05
Message-ID: 200705071205.06089.aklaver@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Monday 07 May 2007 12:00 pm, Tom Lane wrote:
> Adrian Klaver <aklaver(at)comcast(dot)net> writes:
> > With this setup you will have to use an explicit string-
> > date_issued + INTERVAL term|| 'years'. This will involve constructing a
> > string and passing it to INTERVAL.
>
> No, that's a truly awful way to do it. The correct way is to use number
> times interval multiplication, eg
>
> date_issued + term * '1 year'::interval;
>
> This reduces to not much more than a floating-point multiply, whereas
> the other way involves string-forming and string-parsing. Plus you
> can easily use whatever multiplier you like, eg '7 days' if weeks
> strike your fancy.
>
> It might be that converting those columns to interval is the best
> answer, depending on what other processing needs to be done with them.
> But if Rich wants to leave them as numbers, the above is the best way
> to convert them to intervals on-the-fly.
>
> regards, tom lane
Yea, I realized the error of my ways after hitting send. An ounce of proof
reading prevents a pound of oops.
--
Adrian Klaver
aklaver(at)comcast(dot)net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paolo Saudin 2007-05-07 19:25:58 R: Postgres 8.3-dev
Previous Message Andrew Kroeger 2007-05-07 19:03:35 Re: Slow query and indexes...