Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 762B12E2D36 for ; Wed, 5 Dec 2007 03:36:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 94395-02 for ; Wed, 5 Dec 2007 03:36:11 -0400 (AST) Received: from sd-2317.dedibox.fr (sd-2317.dedibox.fr [88.191.17.192]) by postgresql.org (Postfix) with ESMTP id D71B52E00F3 for ; Wed, 5 Dec 2007 03:36:22 -0400 (AST) Received: from sd-2317.dedibox.fr (localhost.localdomain [127.0.0.1]) by sd-2317.dedibox.fr (Postfix) with ESMTP id E4E86B419; Wed, 5 Dec 2007 08:36:20 +0100 (CET) Received: from [192.168.10.1] (ASte-Genev-Bois-153-1-39-100.w83-200.abo.wanadoo.fr [83.200.89.100]) by sd-2317.dedibox.fr (Postfix) with ESMTP id B2C1BAEEC; Wed, 5 Dec 2007 08:36:20 +0100 (CET) Message-ID: <475654EF.8010804@lelarge.info> Date: Wed, 05 Dec 2007 08:36:15 +0100 From: Guillaume Lelarge User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: yohanes@logicsoftware.info CC: pgsql-sql@postgresql.org Subject: Re: Error OID References: <1254.222.124.95.13.1196821462.squirrel@email.powweb.com> In-Reply-To: <1254.222.124.95.13.1196821462.squirrel@email.powweb.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/10 X-Sequence-Number: 29702 Yohanes Purnomo a écrit : > [...] > I create a function: > > CREATE OR REPLACE FUNCTION ReProses() > RETURNS BOOLEAN > AS $$ > > DECLARE > nHasil Numeric; > > BEGIN > CREATE TEMP TABLE tmpTtlRekening WITHOUT OIDS ON COMMIT DROP > AS > SELECT Rekening, SUM(Debet) AS Debet, SUM(Kredit) AS Kredit > FROM Jurnal > GROUP BY Rekening; > > SELECT COALESCE(SUM(Debet - Kredit), 0) > INTO nHasil > FROM tmpTtlRekening; > > -- bla,bla > RETURN '1'; > END; > $$ LANGUAGE 'plpgsql'; > > > Execute Query: > > SELECT ReProses() > > Result is fine, but when i execute again > When you run a function for the first time in the session, PostgreSQL keeps in cache some information... query plans for example. > SELECT ReProses() > > ERROR: relation with OID 41573 does not exist > When you run it a second time, it uses the query plan in cache. As tmpTtlRekening has been drop at the end of the first run, its OID will change but the old OID is still in cache. So PostgreSQL tries to get information from the old temp table. If you don't want that PostgreSQL put the query plan in cache, use the EXECUTE statement. Regards. -- Guillaume. http://www.postgresqlfr.org http://dalibo.com