Repository navigation
Closed
Description
Describe the bug
In the legacy clickhouse-jdbc (v1) driver, JdbcParameterizedQuery.parse() scans the SQL for ?
placeholders and knows about quoted strings (', `, ") and -- / /* */ comments, but it has
no notion of a ClickHouse heredoc literal ($$...$$ / $tag$...$tag$). The contents of a heredoc are
therefore parsed as if they were SQL, so:
- a
?inside a heredoc is counted as a bind parameter — the application cannot supply a value for it,
and the parameter it actually wanted is bound to the wrong position; - a
;inside a heredoc is rejected as a multi-statement query; - a
'inside a heredoc makes the scan run off the end of the statement
(IllegalArgumentException: Missing quote: '); - a
:inside a heredoc can be mistaken for the delimiter of the? :ternary operator, so a real
placeholder before it is silently dropped.
The server accepts all of these statements — a heredoc is a single string literal to it.
Steps to reproduce
With the v1 driver (clickhouse.jdbc.v1=true):
// two parameters are reported instead of one
try (PreparedStatement ps = conn.prepareStatement("select $$a?b$$ as s, ? as n")) {
ps.getParameterMetaData().getParameterCount(); // 2, expected 1
ps.setInt(1, 42); // binds the '?' inside the heredoc
ps.executeQuery(); // fails: value for the second parameter is missing
}Other shapes, same root cause:
conn.prepareStatement("select $$it's$$, ?"); // IllegalArgumentException: Missing quote: '
conn.prepareStatement("select $$a;b$$, ?"); // IllegalArgumentException: Multi-statement query cannot be used ...
conn.prepareStatement("select ?, $$a:b$$"); // the '?' is dropped (read as a ternary operator)Server side, for comparison:
:) SELECT $$a?b$$, $$it's$$, $tag$x;y$tag$
a?b it\'s x;y
Expected behaviour
A heredoc is an opaque string literal: its contents must not be scanned for ? placeholders,
statement separators, quotes, or ternary delimiters. select $$a?b$$ as s, ? as n has exactly one
bind parameter.
Environment
- Client version:
main@ 1a11756 - Language version: Java 8+
- ClickHouse server: 26.5.1.882 (server behaviour is not version-specific here)
Notes
- jdbc-v2 has the analogous defect in
SqlParserFacade.parseParameters— filed separately as [jdbc-v2] PreparedStatement placeholder scan misses // comments and $tag$ heredocs, so a ? inside them is counted as a parameter #3009. com.clickhouse.client.ClickHouseParameterizedQuery(the named-parameter mode of the same v1 driver)
and the v1 JavaCC grammar are heredoc-unaware as well; those are separate defects in separate
modules and are not covered by this report.
Activity
chernser commentedon Aug 18, 2026
Change in V1 requires significant redesign in parser because code is spread across different classes. wontfix here.