"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