pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedSmall problem with embedded comments in a statement
2+ messages / 2 participants
[nested] [flat]
* Small problem with embedded comments in a statement
@ 2006-09-26 09:07 Thomas Kellerer <spam_eater@gmx.net>
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Kellerer @ 2006-09-26 09:07 UTC (permalink / raw)
To: pgsql-jdbc
Hello,
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?
Best regards
Thomas
P.S.: before you ask why I run such a SQL statement: I'm maintaining an
open-source query tool and sometimes unwanted statements are simply un-commented
from within the editor, but the application still sends the whole string that
the user supplied.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Small problem with embedded comments in a statement
@ 2006-09-26 17:36 Kris Jurka <books@ejurka.com>
parent: Thomas Kellerer <spam_eater@gmx.net>
0 siblings, 0 replies; 2+ messages in thread
From: Kris Jurka @ 2006-09-26 17:36 UTC (permalink / raw)
To: Thomas Kellerer <spam_eater@gmx.net>; +Cc: 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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-09-26 17:36 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-09-26 09:07 Small problem with embedded comments in a statement Thomas Kellerer <spam_eater@gmx.net>
2006-09-26 17:36 ` Kris Jurka <books@ejurka.com>
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