From: | "Steve Boyle \(Roselink\)" <boylesa(at)roselink(dot)co(dot)uk> |
---|---|
To: | "Jochem van Dieten" <jochemd(at)oli(dot)tudelft(dot)nl>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: PL/pgSQL: dynamic tablename |
Date: | 2002-01-20 21:47:38 |
Message-ID: | 001e01c1a1fc$1496c420$c55869d5@dualtower |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Jochem,
You will need to use EXECUTE [sql code] from within your function if your
using dynamic sql. For reasons why + examples please see:
http://developer.postgresql.org/docs/postgres/plpgsql-statements.html#PLPGSQ
L-STATEMENTS-EXECUTING-DYN-QUERIES
hih
steve boyle
----- Original Message -----
From: "Jochem van Dieten" <jochemd(at)oli(dot)tudelft(dot)nl>
To: <pgsql-general(at)postgresql(dot)org>
Sent: Sunday, January 20, 2002 9:08 PM
Subject: [GENERAL] PL/pgSQL: dynamic tablename
> I am building a set of functions to manage some trees. I would like to
> use a dynamic tablename. Something like:
>
> CREATE FUNCTION fn_test(varchar, integer, varchar, varchar) RETURNS
> INTEGER AS '
> DECLARE
> beforenode INT4;
> newid INT4;
> BEGIN
> SELECT INTO beforenode lft
> FROM $4
> WHERE ID = $2;
>
> More processing
>
> RETURN newid;
> END;
> ' LANGUAGE 'plpgsql';
>
> Problem is that I always get an error about $4 being used incorrectly.
> If I hardcode the name of the table it works just fine.
>
> Does anybody have any suggestion on how to use a dynamic tablename
> passed as an attribute in a function?
>
> Jochem
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
From | Date | Subject | |
---|---|---|---|
Next Message | mlw | 2002-01-20 21:50:42 | Re: PostgreSQL Licence: GNU/GPL |
Previous Message | Tom Lane | 2002-01-20 21:36:04 | Re: PL/pgSQL: dynamic tablename |