pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Joseph Shraibman <jks@selectacast.net>
Cc: pgsql-bugs@postgresql.org
Cc: pgsql-jdbc@postgresql.org
Cc: Craig Ringer <craig@postnewspapers.com.au>
Subject: Re: [JDBC] BUG #5058: [jdbc] Silent failure with executeUpdate()
Date: Sat, 26 Sep 2009 10:32:19 -0400 (EDT)
Message-ID: <alpine.BSO.2.00.0909261006130.2098@leary.csoft.net> (raw)
In-Reply-To: <4AB27F88.9060202@selectacast.net>
References: <200909151926.n8FJQpDB027963@wwwmaster.postgresql.org>
	<1253067035.19140.24.camel@wallace.localnet>
	<4AB27F88.9060202@selectacast.net>



On Thu, 17 Sep 2009, Joseph Shraibman wrote:

> [when passing a multi-statement sql string to executeUpdate, if a 
> statement after the first is a select, it is silently not fully
> executed.]

Running queries in executeUpdate is not allowed.  If you pass a plain 
select to executeUpdate it complains:  stmt.executeUpdate("SELECT 1");

org.postgresql.util.PSQLException: A result was returned when none was 
expected.

The problem here is that we don't complain if it's not the first part of a 
multi-part statement.  stmt.executeUpdate("/* */; SELECT 1") does not
produce an error, but should, which I believe is the bug in this case.

Since the JDBC driver knows it's going to complain if it sees a query 
result during executeUpdate, it wants to avoid the possibility of the user 
issuing a query which returns a giant dataset and having to process that 
just to error out anyway.  So it passes the statements to the server with 
an additional instruction to say, "I just want the first row back at this 
time".  That way if it is a big query result we'll only get one row 
instead of the whole thing.  The server can implement this by either 
holding the whole resultset on the server or, as in this case, partially 
executing the query and returning control to the driver to see if it wants 
to continue executing it.  So your select is only partially executed, 
getting run for only one row of the "joa" table rather than the whole 
thing as you are expecting.

I intend to change the driver to error out in this case.

Kris Jurka




view thread (5+ messages)

Message-ID: <alpine.BSO.2.00.0909261006130.2098@leary.csoft.net>
Permalink:  ../alpine.BSO.2.00.0909261006130.2098@leary.csoft.net/
Also on:    postgresql.org/message-id/alpine.BSO.2.00.0909261006130.2098@leary.csoft.net

 · 

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: books@ejurka.com, jks@selectacast.net, pgsql-bugs@postgresql.org, craig@postnewspapers.com.au
  Subject: Re: [JDBC] BUG #5058: [jdbc] Silent failure with executeUpdate()
  In-Reply-To: <alpine.BSO.2.00.0909261006130.2098@leary.csoft.net>
  References: <200909151926.n8FJQpDB027963@wwwmaster.postgresql.org> <1253067035.19140.24.camel@wallace.localnet> <4AB27F88.9060202@selectacast.net> <alpine.BSO.2.00.0909261006130.2098@leary.csoft.net>

* 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