Thread: Variable Substitution for table name

Variable Substitution for table name

From
"Samuel J. Sutjiono"
Date:
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
 
 For rec_set IN SELECT DeptdID, VendorName
 from NewView where  (DeptID = iDeptID)
 
I appreciate any help very much.
 

Re: Variable Substitution for table name

From
Stephan Szabo
Date:
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.
>
>