X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 85AF19DC9FD for ; Tue, 21 Mar 2006 20:56:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05147-04 for ; Tue, 21 Mar 2006 20:56:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp-send.myrealbox.com (smtp-send.myrealbox.com [151.155.5.143]) by postgresql.org (Postfix) with ESMTP id 8C4B39DC9BA for ; Tue, 21 Mar 2006 20:56:46 -0400 (AST) Received: from [172.16.1.180] grzm [61.197.227.146] by smtp-send.myrealbox.com with NetMail SMTP Agent $Revision: 1.6 $ on Linux; Tue, 21 Mar 2006 17:56:48 -0700 In-Reply-To: <8333C841129E074E9F83FC80676BA76E0BEBEF@exchg-sea3-03.ant.amazon.com> References: <8333C841129E074E9F83FC80676BA76E0BEBEF@exchg-sea3-03.ant.amazon.com> Mime-Version: 1.0 (Apple Message framework v746.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <06F2BDC4-2FCF-44BA-9DEC-CAAC518CE678@myrealbox.com> Cc: Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: Using a parameter in Interval Date: Wed, 22 Mar 2006 09:56:46 +0900 To: "Davidson, Robert" X-Mailer: Apple Mail (2.746.3) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.448 required=5 tests=[AWL=0.448] X-Spam-Score: 0.448 X-Spam-Level: X-Archive-Number: 200603/340 X-Sequence-Number: 24686 On Mar 22, 2006, at 9:52 , Davidson, Robert wrote: > ERROR: syntax error at or near "CAST" at character 34 > > QUERY: SELECT current_date - INTERVAL (CAST( $1 AS varchar) || ' > weeks') > > CONTEXT: SQL statement in PL/PgSQL function "testing" near line 2 The generally recommended way is something like: test=# select '4'::integer * interval '1 week'; ?column? ---------- 28 days (1 row) or the more SQL compliant: test=# select cast('4' as integer) * interval '1 week'; ?column? ---------- 28 days (1 row) Does that work for you? Michael Glaesemann grzm myrealbox com