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