select into temp tables withough using EXECUTE in plpgsql

From: "Edmund Kleiser" <ekleiser(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: select into temp tables withough using EXECUTE in plpgsql
Date: 2004-11-24 11:18:09
Message-ID: BAY18-F196ACD6D1C22CC65ECD667C5B80@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a query surrounding somthing taht seems to have been a relatively
FAQ. It concerns the use of temporary tables in plpgsql.

Which initially resulted in the good old 'oid xxxx not found' error.

So I learnt from the maliing-list that I should be 'executing' (with EXECUTE
Command) my queries because expressions used in a PL/pgSQL function are only
prepared and saved once (without using execute).

However I would like to select ditinct valuse in my temp table which seem
impossible as:

" SELECT INTO is not currently supported within EXECUTE. So, the only way to
extract a result from a dynamically-created SELECT is to use the FOR ...
EXECUTE form described later."

(http://www.postgresql.org/docs/7.1/static/plpgsql-description.html)

I either cannot find or do not understand the documentation for this " FOR
... EXECUTE form " being described somewhere later in the docuanetation.

So to recap I'm creating a temp table fine.
I'm EXCUTING an insert into the temp table fine.
Then I cannot select from the table
in the form:

SELECT INTO int1 count(distinct(value)) from TEMP1;

Then it happily drops the table (without the select).

Any advice on how to select from a temp table into a variable wuold be
gratefully recieved.

Many Thanks

Edmund

Responses

Browse pgsql-general by date

  From Date Subject
Next Message songsubo 2004-11-24 11:18:19 Insert may fail if i create a primary key on the oid column?
Previous Message Bjørn T Johansen 2004-11-24 11:00:30 Best practice updating data in webapps?