PL/pgSQL: dynamic tablename

From: Jochem van Dieten <jochemd(at)oli(dot)tudelft(dot)nl>
To: pgsql-general(at)postgresql(dot)org
Subject: PL/pgSQL: dynamic tablename
Date: 2002-01-20 21:08:23
Message-ID: 3C4B31C7.7010004@oli.tudelft.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Harald Massa 2002-01-20 21:16:09 Re: Different views with same name for different users
Previous Message alavoor 2002-01-20 21:03:41 PostgreSQL Licence: GNU/GPL