From: Tom Lane <tgl@sss.pgh.pa.us>
To: Unnikrishnan Menon <unnikrishnan.menon@chennai.transys.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Problems with PL/PGSQL - functions
Date: Sun, 13 Jan 2002 11:59:33 -0500
Message-ID: <26109.1010941173@sss.pgh.pa.us> (raw)
In-Reply-To: <008801c19c3f$d588ce70$e90aa8c0@UNNIKRISHNAN>
References: <008801c19c3f$d588ce70$e90aa8c0@UNNIKRISHNAN>
"Unnikrishnan Menon" <unnikrishnan.menon@chennai.transys.net> writes:
> b. query1 :=3D '' Select xyz as variable from S_''|| nextval(sequence)|=
> |'' where abc =3D (some counter value) '' ;
> Execute query1;
You can't use EXECUTE for a SELECT (no way to retrieve the result) nor
for a SELECT INTO (annoying implementation restriction that should be
removed someday). The only way to get a result from a
dynamically-constructed select statement is to use FOR ... EXECUTE.
You do need to use EXECUTEs with any query involving a dynamically
generated table name, so you'll just have to grin and bear it.
But --- does the table actually have to be handled that way? If you
need exactly one such temp table per session, you could use "CREATE TEMP
TABLE" and give the table a fixed name. Then you could skip all the BS
with EXECUTE. Note however that it has to be per session; dropping and
recreating the table mid-session won't work since already-cached query
plans in your plpgsql functions will still point to the old temp table.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, unnikrishnan.menon@chennai.transys.net
Subject: Re: Problems with PL/PGSQL - functions
In-Reply-To: <26109.1010941173@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox