Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4B2FF633238 for ; Wed, 25 Nov 2009 09:42:40 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 76998-04 for ; Wed, 25 Nov 2009 13:42:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id 9637E632F56 for ; Wed, 25 Nov 2009 09:42:32 -0400 (AST) Received: from 222-154-85-191.jetstream.xtra.co.nz ([222.154.85.191] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NDI8Z-00071G-Vn; Thu, 26 Nov 2009 02:42:28 +1300 Message-ID: <4B0D3443.7050902@opencloud.com> Date: Thu, 26 Nov 2009 02:42:27 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Thomas Kellerer CC: pgsql-jdbc@postgresql.org Subject: Re: getUdateCount() vs. RETURNING clause References: <4B0C7CFE.50106@opencloud.com> <4B0D1164.1060006@opencloud.com> <4B0D2014.3060703@opencloud.com> <4B0D2DB0.8020707@opencloud.com> In-Reply-To: <4B0D2DB0.8020707@opencloud.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/30 X-Sequence-Number: 20077 Oliver Jowett wrote: > You never call getMoreResults(), so you are only looking at a single > result, which is either a resultset or an update count, never both. Also, looking at the code a bit more, RETURNING is a bit of a special case. Normally, if you have a command that returns a resultset, the command status is ignored (you generally don't care about the command status of, for example, a SELECT). Presumably that's happening here too. (But the advice regarding getMoreResults() is generally applicable, e.g. if you have a multiple-statement query). You may have more success using something like this: > PreparedStatement pstmt = con.prepareStatement("UPDATE something with no RETURNING clause", new String[] { "some_column" }); > int updateCount = pstmt.executeUpdate(); > ResultSet results = pstmt.getGeneratedKeys(); The driver glues on an appropriate RETURNING clause and arranges for the resulting resultset to appear via getGeneratedKeys(); the update count should still appear as expected. (I haven't actually tried this. caveat emptor) -O