X-Original-To: pgsql-admin-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9F97E9FB228 for ; Mon, 11 Sep 2006 12:03:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 82165-09 for ; Mon, 11 Sep 2006 12:03:35 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.182]) by postgresql.org (Postfix) with ESMTP id 3D0199FA5EA for ; Mon, 11 Sep 2006 12:03:35 -0300 (ADT) Received: by py-out-1112.google.com with SMTP id d80so2219143pyd for ; Mon, 11 Sep 2006 08:03:34 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=TF801OXExG1QOjgvfbaznRQLSyk8FSMoValeYLZxA0k95FLK1ogT97annMvXVwEvMrNSpKmXkBSkcdFydEd+TV4NBv/a5zsH3xcIj6UWJLKtVW3mjM79pl4Skpu6aTaqXFYCNM+tNTwlOG0LKOo79b4IZN0X8yZP2eqz2Vslcrs= Received: by 10.35.53.18 with SMTP id f18mr9025063pyk; Mon, 11 Sep 2006 08:03:34 -0700 (PDT) Received: by 10.35.80.9 with HTTP; Mon, 11 Sep 2006 08:03:34 -0700 (PDT) Message-ID: Date: Mon, 11 Sep 2006 10:03:34 -0500 From: "Aaron Bono" To: "Tom Lane" Subject: Re: SELECT and DATE Function question Cc: "Mike C" , pgsql-admin@postgresql.org In-Reply-To: <22488.1157983704@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_73260_4182059.1157987014109" References: <22488.1157983704@sss.pgh.pa.us> X-Google-Sender-Auth: cd9274a52f6a15a7 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.527 tagged_above=0 required=5 tests=AWL, HTML_30_40, HTML_MESSAGE, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/92 X-Sequence-Number: 23006 ------=_Part_73260_4182059.1157987014109 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/11/06, Tom Lane wrote: > > "Aaron Bono" 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 ================================================================== ------=_Part_73260_4182059.1157987014109 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/11/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Aaron Bono" <postgresql@aranya.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
================================================================== ------=_Part_73260_4182059.1157987014109--