From: Richard Huxton <dev@archonet.com>
To: George A.J <jinujosein@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Re: Temporary tables
Date: Sat, 27 Sep 2003 17:21:35 +0100
Message-ID: <200309271721.35419.dev@archonet.com> (raw)
In-Reply-To: <20030927133139.42953.qmail@web14911.mail.yahoo.com>
References: <20030927133139.42953.qmail@web14911.mail.yahoo.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: dev@archonet.com, jinujosein@yahoo.com
Subject: Re: Temporary tables
In-Reply-To: <200309271721.35419.dev@archonet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox