Re: Temporary tables

From: Richard Huxton <dev(at)archonet(dot)com>
To: "George A(dot)J" <jinujosein(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Temporary tables
Date: 2003-09-27 16:21:35
Message-ID: 200309271721.35419.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-09-27 17:09:25 Re: Temporary tables
Previous Message George A.J 2003-09-27 13:31:39 Temporary tables