Thread: Variable Substitution for table name
Hello all,
Does anybody know whether I can do variable substitution in PostgreSQL function ???
create function Test(text) returns text as '
DECLARE
NewView ALIAS for $1;
BEGIN
DECLARE
NewView ALIAS for $1;
BEGIN
For rec_set IN SELECT DeptdID, VendorName
from NewView where (DeptID = iDeptID)
from NewView where (DeptID = iDeptID)
I appreciate any help very much.
On Sat, 16 Mar 2002, Samuel J. Sutjiono wrote: > Hello all, > > Does anybody know whether I can do variable substitution in PostgreSQL function ??? In plpgsql you can usually use EXECUTE to build a query string and run it in place of the plain query, so something like EXECUTE ''SELECT DeptdID, VendorName from '' || NewView || '' where DeptId=iDeptID'' in place of the select query. > > create function Test(text) returns text as ' > DECLARE > NewView ALIAS for $1; > > BEGIN > > For rec_set IN SELECT DeptdID, VendorName > from NewView where (DeptID = iDeptID) > > I appreciate any help very much. > >