Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id E41FE9FA394 for ; Wed, 20 Dec 2006 10:27:25 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 24316-01 for ; Wed, 20 Dec 2006 10:26:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 9A10E9FA0EE for ; Wed, 20 Dec 2006 10:26:52 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id BC1ED742CB; Wed, 20 Dec 2006 14:26:43 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id A03E5FF04; Wed, 20 Dec 2006 14:26:42 +0000 (GMT) Message-ID: <45894822.2060605@archonet.com> Date: Wed, 20 Dec 2006 14:26:42 +0000 From: Richard Huxton User-Agent: Thunderbird 1.5.0.8 (X11/20061115) MIME-Version: 1.0 To: Richard Ray Cc: pgsql-sql@postgresql.org Subject: Re: Help with quotes in plpgsql References: <8C5B026B51B6854CBE88121DBF097A866A4982@ehost010-33.exch010.intermedia.net> <14125.1166574420@sss.pgh.pa.us> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/157 X-Sequence-Number: 27113 Richard Ray wrote: > It makes sense when ya'll explain it > It never sounds that good when I'm talkin to myself > That solves my problem but not my ignorance > I'm still curious about how would I properly quote > > create or replace function test(integer) returns setof text as $$ > declare > a record; > begin > select into a now() - interval '$1 day'; ^^^^^^^^ The basic mistake is that you're assuming strings interpolate variables. This isn't true in plpgsql, never has been and probably never will. So you can't do: my_msg := 'Hello $1, how are you?'; You need: my_msg := 'Hello ' || $1 || ', how are you?'; Don't forget most variables don't have a leading dollar sign. Imagine you'd defined a variable called "day" in test() - you wouldn't expect that to be interpolated, would you? -- Richard Huxton Archonet Ltd