Skip to content

invalid parameter count with CTEs in 0.92 #2595

Closed

Description

@dpsutton

Likely should be included in #2576

jdbc-v2 0.9.2

Description

Running queries with CTEs and parameters results in errors because the PreparedStatement thinks it has 0 parameters

Steps to reproduce

Working in 0.8.4:

❯ clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.8.4"}}}' -J"$(socket-repl 6084)"
user=> (defn query-info [sql]
         ;; parse param names and replace {{id}} with ?
         (with-open [conn (java.sql.DriverManager/getConnection "jdbc:clickhouse://localhost:8123" "default" "password")
                     stmt (.prepareStatement conn sql)]
           (.. stmt getParameterMetaData getParameterCount)))
#'user/query-info
user=> (query-info "SELECT `source`.`id` AS `id`,
                      `source`.`val` AS `val` FROM
               (with base as (\n select 1 id, 'abc' val\n)\nselect * from base)
               AS `source`
               WHERE `positionCaseInsensitiveUTF8`(`source`.`val`, ?) > ? LIMIT 2000")
2

Broken in 0.9.2:

❯ clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.9.2"}}}' -J"$(socket-repl 6092)"
user=> (defn query-info [sql]
         ;; parse param names and replace {{id}} with ?
         (with-open [conn (java.sql.DriverManager/getConnection "jdbc:clickhouse://localhost:8123" "default" "password")
                     stmt (.prepareStatement conn sql)]
           (.. stmt getParameterMetaData getParameterCount)))
#'user/query-info
user=> (query-info "SELECT `source`.`id` AS `id`,
                      `source`.`val` AS `val` FROM
               (with base as (\n select 1 id, 'abc' val\n)\nselect * from base)
               AS `source`
               WHERE `positionCaseInsensitiveUTF8`(`source`.`val`, ?) > ? LIMIT 2000")
0

Expected Behaviour

The 0.9.2 driver should recognize the positionCaseInsensitiveUTF8(val, ?) > ? expression after the CTE. This is the way that we do a "string includes" operation.

Code Example

shown above in repro

Environment

  • Cloud
  • Client version:
  • Language version:
  • OS:

ClickHouse Server

just running clickhouse server latest in docker

Activity

  1. added
    jdbc
    sql-parser
    on Sep 17, 2025
  2. added this to the 0.9.3 milestone on Sep 17, 2025
  3. rileythomp commented on Sep 23, 2025

    @rileythomp

    This happens without positionCaseInsensitiveUTF8:

    $ clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.9.2"}}}'
    Clojure 1.12.2
    user=> (let [conn (java.sql.DriverManager/getConnection "jdbc:clickhouse://localhost:8123" "default" "")
            sql "SELECT id, val FROM ( WITH foo AS ( SELECT 1 id, 'abc' val ) SELECT * FROM foo ) WHERE val = ? LIMIT 1048575"
            stmt (.prepareStatement conn sql)]
        (.setString stmt 1 "abc")
        (let [rs (.executeQuery stmt)]
          (while (.next rs)
            (println (.getString rs 1) (.getString rs 2)))))
    Execution error (ArrayIndexOutOfBoundsException) at com.clickhouse.jdbc.PreparedStatementImpl/setString (PreparedStatementImpl.java:210).
    Index 0 out of bounds for length 0
    
  4. added
    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

    bugjdbcqueriessql-parser

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions