pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: DELETE ... RETURNING
Date: Mon, 13 Jul 2009 23:54:55 +0200
Message-ID: <h3gafc$51d$1@ger.gmane.org> (raw)
In-Reply-To: <4A5BAA29.9000004@opencloud.com>
References: <h3g2rn$dn8$1@ger.gmane.org>
	<226a19190907131251m6c3786f5id8e8025f5c53cf66@mail.gmail.com>
	<h3g536$kq4$1@ger.gmane.org>
	<4A5BAA29.9000004@opencloud.com>

Oliver Jowett wrote on 13.07.2009 23:42:
> Thomas Kellerer wrote:
> 
>> At least executeUpdate() should not throw an exception.
> 
> Wrong, see the javadoc:
Oops ;)

> Your SQL statement is returning a ResultSet object, so executeUpdate
> correctly throws an exception.
> 
> Use executeQuery() or execute().

But execute() will not give the information about the returned IDs as 
getMoreResults() always returns false.

And in my test getUpdateCount() returned -1 even though rows were deleted.

The following code will print "deleted: -1" and nothing more.

But my understanding is, that it should print "deleted: 3", and then iterate 
over the returned ids (but at least show the correct update count)

Statement stmt = con.createStatement();

stmt.executeUpdate(
"CREATE TABLE test_delete (id integer primary key, some_data varchar(100))"
);
stmt.executeUpdate("insert into test_delete values (1, 'first row')");
stmt.executeUpdate("insert into test_delete values (2, 'second row')");
stmt.executeUpdate("insert into test_delete values (3, 'third row')");
con.commit();

stmt.execute("delete from test_delete returning id");
System.out.println("deleted: " + stmt.getUpdateCount());
if (stmt.getMoreResults())
{
   System.out.println("has result");
   rs = stmt.getResultSet();
   while (rs.next())
   {
     System.out.println(rs.getObject(1));
   }
}


Thomas




view thread (10+ messages)  latest in thread

Message-ID: <h3gafc$51d$1@ger.gmane.org>
Permalink:  ../h3gafc$51d$1@ger.gmane.org/
Also on:    postgresql.org/message-id/h3gafc$51d$1@ger.gmane.org

 · 

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: spam_eater@gmx.net
  Subject: Re: DELETE ... RETURNING
  In-Reply-To: <h3gafc$51d$1@ger.gmane.org>
  References: <h3g2rn$dn8$1@ger.gmane.org> <226a19190907131251m6c3786f5id8e8025f5c53cf66@mail.gmail.com> <h3g536$kq4$1@ger.gmane.org> <4A5BAA29.9000004@opencloud.com> <h3gafc$51d$1@ger.gmane.org>

* 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