Re: Temporary tables - Mailing list pgsql-sql

From Richard Huxton
Subject Re: Temporary tables
Date
Msg-id 200309271721.35419.dev@archonet.com
Whole thread Raw
In response to Temporary tables  ("George A.J" <jinujosein@yahoo.com>)
List pgsql-sql
On Saturday 27 September 2003 14:31, George A.J wrote:
> hi,
>
> I am using postgresql 7.3.2. Is there any function to determine
> whether a table exists in the database.Or is there any function
> that returns the current temp schema.
> I am using a pl/pgsql function that create and drop a temporary table.
> The procedure run correctly for the first time for each database
> connection. If I run the same procedure second time in the same connection
> it produces the error
>
> "ERROR:  pg_class_aclcheck: relation 219389 not found
> WARNING:  Error occurred while executing PL/pgSQL function testFun
> WARNING:  line 20 at SQL statement "

This is because plpgsql is "compiled" and so the reference to tempTable gets 
fixed the first time it is called. In your case, the oid was 219389.

Now, the second time you call the function, the temp table gets re-created, 
gets a new OID and the old reference is no longer valid your insert line.

There are two solutions:
1. Use pltcl/plperl or some other interpreted language that doesn't compile in 
table references.
2. Build your insert statement using EXECUTE ''INSERT INTO tempTable ''...

This second passes the query string into the parser, so it works just fine for 
your example. I think some of this is covered in the manuals, you can 
certainly find plenty on it in the archives.

--  Richard Huxton Archonet Ltd


pgsql-sql by date:

Previous
From: "George A.J"
Date:
Subject: Temporary tables
Next
From: Tom Lane
Date:
Subject: Re: Temporary tables