Обсуждение: Variable Substitution for table name

Поиск
Список
Период
Сортировка

Variable Substitution for table name

От
"Samuel J. Sutjiono"
Дата:
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: [GENERAL] Variable Substitution for table name

От
Stephan Szabo
Дата:
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.
>
>