Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id C98124763E0; Sat, 16 Mar 2002 19:07:56 -0500 (EST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 658A0D5FA; Sat, 16 Mar 2002 16:07:59 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 573205BFD; Sat, 16 Mar 2002 16:07:59 -0800 (PST) Date: Sat, 16 Mar 2002 16:07:59 -0800 (PST) From: Stephan Szabo To: "Samuel J. Sutjiono" Cc: , Subject: Re: Variable Substitution for table name In-Reply-To: <00e901c1cd34$edd88cb0$110a010a@headquarters.wcgroup.com> Message-ID: <20020316160551.W74854-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200203/878 X-Sequence-Number: 22250 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. > >