X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 739A5D1B527 for ; Sat, 27 Sep 2003 16:21:49 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 47806-02 for ; Sat, 27 Sep 2003 13:21:39 -0300 (ADT) Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net [194.217.242.91]) by svr1.postgresql.org (Postfix) with ESMTP id 457B2D1B503 for ; Sat, 27 Sep 2003 13:21:38 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-33.mail.demon.net with esmtp (Exim 3.35 #1) id 1A3HpB-000FqF-0X; Sat, 27 Sep 2003 17:21:37 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id C589F179D9; Sat, 27 Sep 2003 17:21:36 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 1D691179D8; Sat, 27 Sep 2003 17:21:36 +0100 (BST) From: Richard Huxton To: "George A.J" , pgsql-sql@postgresql.org Subject: Re: Temporary tables Date: Sat, 27 Sep 2003 17:21:35 +0100 User-Agent: KMail/1.5 References: <20030927133139.42953.qmail@web14911.mail.yahoo.com> In-Reply-To: <20030927133139.42953.qmail@web14911.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200309271721.35419.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/349 X-Sequence-Number: 15327 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