Re: Variable Substitution for table name

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: "Samuel J(dot) Sutjiono" <ssutjiono(at)wc-group(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Variable Substitution for table name
Date: 2002-03-17 00:07:59
Message-ID: 20020316160551.W74854-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql


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.
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Miguel Omar Carvajal 2002-03-17 01:54:54 update cursor
Previous Message Tom Lane 2002-03-16 23:01:52 Re: problem with array of boxes

Browse pgsql-sql by date

  From Date Subject
Next Message Dan Langille 2002-03-17 00:18:11 Re: why the big difference on this explain analyze?
Previous Message Dan Langille 2002-03-16 22:22:55 Re: why the big difference on this explain analyze?