pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Joseph Shraibman <jks@selectacast.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: executeUpdate("SELECT INTO")
Date: Tue, 15 Mar 2005 18:56:35 +1300
Message-ID: <42367913.8070704@opencloud.com> (raw)
In-Reply-To: <42366B61.9030203@selectacast.net>
References: <42366B61.9030203@selectacast.net>

Joseph Shraibman wrote:
> How come executeUpdate() always returns 1 when the sql is SELECT ... 
> INTO TEMP tablename ?  I'm using pg 7.4.7

I just tried the CVS driver against 7.4.6 and 8.0.0 servers, and both 
return 0 in this case, regardless of the actual number of rows inserted. 
I don't have a 7.4.7 build to hand, but I'd expect it to behave the same 
as 7.4.6.

Returning 0 is ok according to the JDBC spec, which says that 
executeUpdate returns "either the row count for INSERT, UPDATE or DELETE 
statements, or 0 for SQL statements that return nothing". We can't 
return a row count here anyway, as the server doesn't tell us the number 
of rows inserted by a SELECT INTO.

If you're seeing a return value of 1, that does seem wrong. Can you 
provide some test code showing the problem? We'd also need to know 
exactly which driver build you are using.

The test code I used is attached.

-O

Attachments:

TestSelectInto.java (text/plain, 561B) download import java.sql.*; // Run with one argument: a JDBC url to connect to. public class TestSelectInto { public static void main(String[] args) throws Exception { Class.forName("org.postgresql.Driver"); Connection c = DriverManager.getConnection(args[0]); Statement s = c.createStatement(); s.executeUpdate("CREATE TEMP TABLE t1 (i integer); INSERT INTO t1(i) VALUES (1); INSERT INTO t1(i) VALUES (2)"); int count = s.executeUpdate("SELECT i INTO TEMP TABLE t2 FROM t1"); System.out.println("Update count: " + count); s.close(); c.close(); } }

view thread (2+ messages)

Message-ID: <42367913.8070704@opencloud.com>
Permalink:  ../42367913.8070704@opencloud.com/
Also on:    postgresql.org/message-id/42367913.8070704@opencloud.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: oliver@opencloud.com, jks@selectacast.net
  Subject: Re: executeUpdate("SELECT INTO")
  In-Reply-To: <42367913.8070704@opencloud.com>
  References: <42366B61.9030203@selectacast.net> <42367913.8070704@opencloud.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