Re: a possible bug in postgresql jdbc driver

From: Kris Jurka <books(at)ejurka(dot)com>
To: Pawel Pastula <pawelp76(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: a possible bug in postgresql jdbc driver
Date: 2009-03-10 17:35:38
Message-ID: 49B6A4EA.5060905@ejurka.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Pawel Pastula wrote:
> Hi Kris
>

Please send general questions to the pgsql-jdbc(at)postgresql(dot)org mailing
list rather than to individual developers.

> I think I've found a bug in jdbc driver.
> I need to execute a query which is actually a list of queries and some
> of them drop tables, other update tables and one of them queries data
> with select.
> Imagine the following query (report):
>
> drop table if exists test_table;
> select * into test_table from other_table;
> select * from test_table;
>
> Of course it looks very simple but it's only for testing purposes. My
> queries are more demanding with lots of select * into temp table etc.
> I figured out that in order to get data from test_table I need to
> actually call getResultSet() 3 times. Therefore I wrote some simple
> 'result set walker' to get the latest result set returned by the query.
> And it's fine.
>
> However in case of this report stmt.executeQuery() would be more
> convenient since we expect to receive some data.
> And this is the place where the problem is. It throws exception just
> because after the query is executed there is a check whether result set
> is not null.
> And the problem is, that only the first result set is taken into
> account. The rest is ignored. And in my case the first query has no
> result set, it only has update count, the same with the second query.
> Only the third one has a result set.
> Therefore the check shouldn't be done whether there is a result set and
> whether it's not null for the first subquery but whether there is a
> result set for any subquery in this query.

See the javadoc for Statement.executeQuery, it says it should throw a
SQLException if, "the given SQL statement produces anything other than a
single ResultSet object." As you've noted it has produced other results
(update counts) and therefore it must throw the exception.

Kris Jurka

Browse pgsql-jdbc by date

  From Date Subject
Next Message Peter 2009-03-11 13:43:11 Totally weird behaviour in org.postgresql.Driver
Previous Message Tom Lane 2009-03-10 17:20:47 Re: Query much slower when run from postgres function