Re: SELECT and DATE Function question

From: "Aaron Bono" <postgresql(at)aranya(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Mike C" <smith(dot)not(dot)western(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: SELECT and DATE Function question
Date: 2006-09-11 15:03:34
Message-ID: bf05e51c0609110803k2e9679d2ma200b00fa10f4651@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 9/11/06, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> "Aaron Bono" <postgresql(at)aranya(dot)com> writes:
> > Use:
>
> > select start_date + (cast(number_of_days as text) || ' days')::interval
> from
> > blah
>
> This is a pretty awful way to do it, much better is
>
> select start_date + number_of_days * '1 day'::interval ...
>
> which reduces to basically one multiplication instead of conversion to
> text, text string append, parse interval string value (relying on a
> couple of undocumented cast abilities).

I knew there was a better way but I forgot what it was and couldn't find it
in the documentation.

Could the documentation be updated with this example? This question appears
every month or so and I know it is very useful to many people.

Thanks!

==================================================================
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.com
http://codeelixir.com
==================================================================

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Mr. Dan 2006-09-11 18:55:26 COPY FROM command v8.1.4
Previous Message Marco Bizzarri 2006-09-11 14:49:37 Re: [GENERAL] Problem with lo_export() and lo_import() from remote machine.