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@oli.tudelft.nl>
To: <pgsql-general@postgresql.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
>