SELECT INTO Troubles

From: Brian Troxell <trox(at)mindspring(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: SELECT INTO Troubles
Date: 2001-01-08 23:10:57
Message-ID: 3A5A4901.A6E9BA05@mindspring.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello again everyone. This is the next message in my series of troubles
regarding EXECUTE and SELECT INTO (or CREATE TABLE). Hopefully the list
will be as helpful and informative as with my previous queries.

I have a PG/plSQL function get_attribute()) that does a simple lookup
using this code:
EXECUTE ''CREATE TEMPORARY TABLE random_tab (item) AS SELECT '' ||
quote_ident(v_column) || '' FROM '' ||
quote_ident(v_table_name) || '' WHERE '' || v_key_sql;
v_return := random_tab.item;
raise NOTICE ''v_return = %'', v_return;
DROP TABLE random_tab;

In my test routine, I call this get_attribute() function, followed by
another set_attribute() function, followed by get_attribute() again to
make sure the value was changed.

The problem is with the second call to get_attribute()...I get this
error:
psql:lop2:15: ERROR: Relation 74176 does not exist

But if I remove the DROP TABLE statement from the get_attribute()
function, the second call to it fails with this error:
psql:lop2:15: ERROR: Relation 'random_tab' already exists

So I tried it again, taking out the EXECUTE and just hard-coding the
SELECT statement, and get the same errors.

This sounds like a total Catch-22 to me, which must mean I'm doing
something wrong. Help!!!!!

Thanks in advance!

Brian Troxell
trox(at)mindspring(dot)com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lee Joramo 2001-01-09 00:26:03 COPY error: pqReadData() -- backend closed the channel unexpectedly
Previous Message The Hermit Hacker 2001-01-08 23:06:18 Re: pgsql & mnogosearch