Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.erje.net!newsfeed.utanet.at!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mail From: "Laurenz Albe" Newsgroups: comp.databases.postgresql References: Subject: Re: Stored procedure and dynamic statements? Date: Tue, 3 May 2011 10:04:05 +0200 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6090 Organization: dienste.wien.at ISP Message-ID: <1304409866.536393@proxy.dienste.wien.at> X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/) Lines: 27 NNTP-Posting-Host: 141.203.254.23 X-Trace: 1304409868 aconews.univie.ac.at 34944 141.203.254.23 X-Complaints-To: abuse@univie.ac.at Xref: x330-a1.tempe.blueboxinc.net comp.databases.postgresql:110 durumdara wrote: > I want to ask that is pg supports dynamic usage of SQL, or variable as > SQL (or part of SQL) statement? > > :tablename = call CreateTempTable; > insert into :tablename .... > drop table :tablename > > or (FireBird like cursor handling): > > sql = "select * from " || :tablename || " where..." > for select :sql .... > ... SQL itself does not support that, but there are things like that in psql: \set varname value CREATE TABLE :varname (id integer); INSERT INTO :varname VALUES (1); Does that help? Yours, Laurenz Albe