Re: Small problem with embedded comments in a statement

From: Kris Jurka <books(at)ejurka(dot)com>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Small problem with embedded comments in a statement
Date: 2006-09-26 17:36:05
Message-ID: Pine.BSO.4.63.0609261230290.32358@leary2.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Tue, 26 Sep 2006, Thomas Kellerer wrote:

> When running the following query:
>
> String sql = "select * from table1\n" +
> "--select * from table2;\n" +
> "--select * from table3";
> I get an error:
> org.postgresql.util.PSQLException: Multiple ResultSets were returned by the
> query.
>
> But as the second and third SELECT are behing a comment, they should be
> ignored, right? Actually when removing the semicolon after table2, then
> everything works fine.
>
> Is this a bug in the JDBC driver, or is this intended behaviour?
>

Yes, it's a bug, but one that's likely to be here for a while. Right now
the JDBC driver splits queries on semicolons because you cannot submit
multipart queries via the extended query protocol. So it splits them at
the semicolons and issues them separately. The parsing code is very
simple and doesn't handle -- or /* */ comments or dollar quotes.

For your case you could change from using executeQuery to plain execute()
which supports returning multiple resultsets, but there are plenty of
other bugs that cannot be so easily worked around here.

Kris Jurka

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jeanna Geier 2006-09-26 18:57:56 Re: Beginner's Question: No pg_hba.conf entry for host...SSL Off
Previous Message Mark Lewis 2006-09-26 16:35:50 Re: Bind message