X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3BBC2528E0 for ; Mon, 20 Jun 2005 08:30:28 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13569-02 for ; Mon, 20 Jun 2005 11:30:25 +0000 (GMT) Received: from relais.videotron.ca (relais.videotron.ca [24.201.245.36]) by svr1.postgresql.org (Postfix) with ESMTP id 92866528BD for ; Mon, 20 Jun 2005 08:30:21 -0300 (ADT) Received: from [192.168.1.101] ([24.202.23.128]) by VL-MO-MR011.ip.videotron.ca (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0IID0052YRYMZZ@VL-MO-MR011.ip.videotron.ca> for pgsql-jdbc@postgresql.org; Mon, 20 Jun 2005 07:30:22 -0400 (EDT) Date: Mon, 20 Jun 2005 07:35:57 -0400 From: David Gagnon Subject: Re: Problems with temporary tables created in callable functions In-reply-to: To: Akhil Srinivasan Cc: pgsql-jdbc@postgresql.org Message-id: <42B6AA1D.3060809@siunik.com> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) References: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.018 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/102 X-Sequence-Number: 13064 Hi, Temporary table a tricky in postgresql you must use: EXECUTE '' CREATE TEMP TABLE TMP_IC ( ICNUM VARCHAR(20) primary key ) ON COMMIT DROP''; And for your sql : statement := '' INSERT INTO TMP_IC SELECT ICNUM FROM IC''; EXECUTE STATEMENT; The problem is that the SQL planner keeps the plan for deleted temp table. Using the EXECUTE statement avoid caching in the planner. This is the official way to use temp table in postgresql. Look in the FAQ (I think,) everything is explained there. Ciao /David Akhil Srinivasan wrote: > Hi > I have a an application that uses a lot of stored functions, some of > them which create temporary tables and refcursors that point to the > tables. Something that comes up occasionally are errors like > > This is when we have some code in the function to delete existing > temporary tables. > ERROR: relation with OID xxxxx does not exist. > ERROR: relation "TEMPSTOCKVALUEALERT" already exists > > When we comment that code we get errors like > ERROR: relation "TEMPSTOCKANALYSIS" already exists. This happens every > second call to the function. > > In the jdbc call code we have setAutoCommit to false, And I have tried > a couple of options when preparing the call like > > CallableStatement proc = con.prepareCall("{ ? = call > \"queryStockAnalysisSingle\" ( ?,?,?,? ) }" > ,ResultSet.CONCUR_READ_ONLY,ResultSet.CLOSE_CURSORS_AT_COMMIT); > > CallableStatement proc = con.prepareCall("{ ? = call > \"queryStockAnalysisSingle\" ( ?,?,?,? ) }" > ,ResultSet.CONCUR_READ_ONLY,ResultSet.HOLD_CURSORS_OVER_COMMIT); > > None of them seem to work. Has anybody faced this problem? And > hopefully cone up with a usable fix. > The application has a commons-dbcp maintaining a connection pool to > the database server. The jdbc driver used is the jdbc3. THe database > version is 7.4.x. It has been deployed on a Debian Linux system with > kernel version 2.6.8. > > Thanks > Akhil Srinivasan > > >