From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Richard Ray <rray(at)mstc(dot)state(dot)ms(dot)us> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Help with quotes in plpgsql |
Date: | 2006-12-20 14:26:42 |
Message-ID: | 45894822.2060605@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Erik Jones | 2006-12-20 15:46:51 | Re: join/group/count query. |
Previous Message | Richard Ray | 2006-12-20 14:10:53 | Re: Help with quotes in plpgsql |