dynamic SQL - variable substitution in plpgsql

From: km <km(at)mrna(dot)tn(dot)nic(dot)in>
To: pgsql-general(at)postgresql(dot)org
Subject: dynamic SQL - variable substitution in plpgsql
Date: 2006-12-06 20:23:46
Message-ID: 20061206202346.GA18082@mrna.tn.nic.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

i could not do variable substitution in plpgsql procedure.
The variable names are taken as it is but not substituted in the SQL query.
what could be the problem ?

code looks like this:
------------------------------------------------------------------
CREATE OR REPLACE FUNCTION test(a text) RETURNS SETOF RECORD AS $$
DECLARE
a text;
b text;
BEGIN

IF a = 'odd' THEN
b := 10;
c := 30;
ELIF a = 'even' THEN
b := 20;
c := 40;
END IF;

FOR result IN "SELECT x,y,z FROM mydata WHERE x = a AND y < b AND z > c" LOOP
RETURN NEXT result;
END LOOP;

END;
$$ language 'pgplsql';
-------------------------------------------------------------
tia
KM

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tony Caduto 2006-12-06 20:33:37 Re: dynamic SQL - variable substitution in plpgsql
Previous Message wheel 2006-12-06 20:16:35 Re: Restore database from files (not dump files)?