Skip to content

clickhouse-jdbc (v1): a '?' inside a heredoc literal is counted as a bind parameter #3035

Closed

Description

@polyglotAI-bot

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

Activity

  1. chernser commented on Aug 18, 2026

    @chernser
    Contributor

    Change in V1 requires significant redesign in parser because code is spread across different classes. wontfix here.

  2. added
    client
    legacy
    jdbc
    queries
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclientjdbclegacyquerieswontfix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions