Re: dynamic SQL - variable substitution in plpgsql

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: km(at)mrna(dot)tn(dot)nic(dot)in
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: dynamic SQL - variable substitution in plpgsql
Date: 2006-12-07 09:13:06
Message-ID: 4577DB22.4010500@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

km wrote:
> 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 ?

Does this example even compile? I doubt that...

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

I think you meant:

DECLARE
b text;
c text;

You redeclared a and never declared c.

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

--
Alban Hertroys
alban(at)magproductions(dot)nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

// Integrate Your World //

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Henrik Zagerholm 2006-12-07 09:21:20 Uninstall pg_trgm
Previous Message Willy-Bas Loos 2006-12-07 09:08:50 Cast boolean to text