pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Fernando Hartmann <fh@sadig.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Num of returned ROWS
Date: Wed, 08 Jun 2005 22:49:38 +0000
Message-ID: <42A77602.5030503@opencloud.com> (raw)
In-Reply-To: <d86l4d$45u$1@sea.gmane.org>
References: <d84t1f$pj1$1@sea.gmane.org>
	<42A62275.2020900@opencloud.com>
	<d86l4d$45u$1@sea.gmane.org>

Fernando Hartmann wrote:

>>> set datestyle to ISO,DMY;

BTW, you shouldn't fiddle with DateStyle; the driver relies on it being 
ISO (so this particular datestyle is OK, but consider using 
PreparedStatement.setDate() instead).

>>> create table table1 as select F1, sum(F10) from table where F1 between
>>> '1/1/2001' and '31/12/2004' group by F1;
>>> select count(*) from table1
>>>
>>>    But the executeUpdate always return 0, even when the cont(*) return
>>> a number other than 0.

>     Ok, but and the last line ? The select count ? They don't return the 
> number of rows too!

Ah, I thought you meant you were looking at the resultset generated by 
the SELECT and it was non-zero..

There is no updated-row-count associated with a SELECT query. But that's 
not why you see a 0 returned; it's because there are two sets of results 
returned by the above multi-statement query, and you're only seeing the 
results of the first query if you use executeUpdate().

You should be using getMoreResults() to step forward to the results of 
the second query (the SELECT) and then inspect the returned resultset 
(getResultSet()). getUpdateCount() after getMoreResults() should return 
-1 ("no update count, this has a ResultSet"); see the JDBC javadoc.

(this assumes you're using a recent driver which follows the spec; 
earlier drivers were a bit fuzzier about how they handled multiple results)

-O



view thread (5+ messages)

Message-ID: <42A77602.5030503@opencloud.com>
Permalink:  ../42A77602.5030503@opencloud.com/
Also on:    postgresql.org/message-id/42A77602.5030503@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, fh@sadig.com
  Subject: Re: Num of returned ROWS
  In-Reply-To: <42A77602.5030503@opencloud.com>
  References: <d84t1f$pj1$1@sea.gmane.org> <42A62275.2020900@opencloud.com> <d86l4d$45u$1@sea.gmane.org> <42A77602.5030503@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