Skip to content

CTE inside of a subquery does not work #2442

@rileythomp

Description

@rileythomp

Description

In 0.8.6 a query with a CTE inside of a subquery fails. It worked with 0.8.4 and works with clickhouse-client.

Found while investigating metabase/metabase#59166

Steps to reproduce

  1. Start a ClickHouse container

  2. Start a Clojure repl with 0.8.6:
    $ clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.8.6"}}}'

  3. Execute the query

(let [sql "select * from ( with x as ( select 9 ) select * from x );"]
  (with-open [conn (java.sql.DriverManager/getConnection "jdbc:clickhouse://localhost:8123" "default" "")
              stmt (.createStatement conn)]
    (.execute stmt sql)
    (with-open [rs (.getResultSet stmt)]
      (while (.next rs)
        (println (.getObject rs 1))))))
  1. See that the query errors

  2. The code in 3. works if 2. is done with clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.8.4"}}}'

Error Log or Exception StackTrace

line 2:11 no viable alternative at input 'select*from(withxas('
Execution error (NullPointerException) at user/eval166 (REPL:5).
Cannot invoke "java.sql.ResultSet.close()" because "rs" is null

Expected Behaviour

Query succeeds and returns expected results

9

Environment

  • Client version: 0.8.6
  • Language version: Clojure 1.12.0
  • OS: Sequoia 15.3.1

ClickHouse Server

  • ClickHouse Server version: 25.2.2.39

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions