pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
executeUpdate("SELECT INTO")
2+ messages / 2 participants
[nested] [flat]

* executeUpdate("SELECT INTO")
@ 2005-03-15 04:58  Joseph Shraibman <jks@selectacast.net>
  0 siblings, 1 reply; 2+ messages in thread

From: Joseph Shraibman @ 2005-03-15 04:58 UTC (permalink / raw)
  To: pgsql-jdbc

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: executeUpdate("SELECT INTO")
@ 2005-03-15 05:56  Oliver Jowett <oliver@opencloud.com>
  parent: Joseph Shraibman <jks@selectacast.net>
  0 siblings, 0 replies; 2+ messages in thread

From: Oliver Jowett @ 2005-03-15 05:56 UTC (permalink / raw)
  To: Joseph Shraibman <jks@selectacast.net>; +Cc: pgsql-jdbc

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(); } }
^ permalink raw reply [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-03-15 05:56 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-03-15 04:58 executeUpdate("SELECT INTO") Joseph Shraibman <jks@selectacast.net>
2005-03-15 05:56 ` Oliver Jowett <oliver@opencloud.com>

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