Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 8203A475897 for ; Mon, 29 Apr 2002 10:04:59 -0400 (EDT) Received: from candle.pha.pa.us (216-55-132-35.dsl.san-diego.abac.net [216.55.132.35]) by postgresql.org (Postfix) with ESMTP id 3147C475C26 for ; Mon, 29 Apr 2002 10:04:08 -0400 (EDT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.10.1) id g3TE46A26180; Mon, 29 Apr 2002 10:04:06 -0400 (EDT) From: Bruce Momjian Message-Id: <200204291404.g3TE46A26180@candle.pha.pa.us> Subject: Re: Temporary table weirdness In-Reply-To: To: Joseph Barillari Date: Mon, 29 Apr 2002 10:04:06 -0400 (EDT) Cc: pgsql-sql X-Mailer: ELM [version 2.4ME+ PL97 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Archive-Number: 200204/357 X-Sequence-Number: 7621 Yes, this is a known problem. You need to use plpgsql EXECUTE command for any function query that deals with temp tables. --------------------------------------------------------------------------- Joseph Barillari wrote: Checking application/pgp-signature: FAILURE -- Start of PGP signed section. > Hi, > > I have a function that creates and destroys temporary tables in the > course of its work, and have run into trouble if the function > is executed more than once during a database session. A small > proof-of-concept is attached below: > > cal=> create or replace function frob() returns integer as 'begin create temporary table foo(bar INT); insert into foo (bar) values (1); drop table foo; return 1; end;' language 'plpgsql'; > CREATE > > (seems pretty standard) > > cal=> select frob(); > frob > ------ > 1 > (1 row) > > (OK so far...) > > cal=> select frob(); > NOTICE: Error occurred while executing PL/pgSQL function frob > NOTICE: line 1 at SQL statement > ERROR: Relation 68141 does not exist > > On the second call, PostgreSQL chokes. Any suggestions as to why > would be appreciated. > > Oddly enough, redefining the function eliminates the error for the > next function call. > > Thanks, > > Joe -- End of PGP section, PGP failed! -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026