pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Gagnon <dgagnon@siunik.com>
To: Akhil Srinivasan <akhilss@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Problems with temporary tables created in callable functions
Date: Mon, 20 Jun 2005 07:35:57 -0400
Message-ID: <42B6AA1D.3060809@siunik.com> (raw)
In-Reply-To: <ad76b9f2050619232793a567d@mail.gmail.com>
References: <ad76b9f2050619232793a567d@mail.gmail.com>

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
>
>
>




view thread (5+ messages)  latest in thread

Message-ID: <42B6AA1D.3060809@siunik.com>
Permalink:  ../42B6AA1D.3060809@siunik.com/
Also on:    postgresql.org/message-id/42B6AA1D.3060809@siunik.com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: dgagnon@siunik.com, akhilss@gmail.com
  Subject: Re: Problems with temporary tables created in callable functions
  In-Reply-To: <42B6AA1D.3060809@siunik.com>
  References: <ad76b9f2050619232793a567d@mail.gmail.com> <42B6AA1D.3060809@siunik.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