Skip to content

Recursive CTE statements can't be executed due to parser error #2844

@rileythomp

Description

@rileythomp

Description

A recursive CTE can't be executed

Steps to reproduce

clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.9.7"} org.lz4/lz4-java {:mvn/version "1.8.0"}}}'
(do
  (import '[java.sql DriverManager])
  (let [sql "WITH RECURSIVE t AS ( SELECT 1 AS n UNION ALL SELECT n + 1 FROM t WHERE n < 3 ) SELECT * FROM t;"]
    (with-open [conn (DriverManager/getConnection "jdbc:clickhouse://localhost:8123/default" "default" "")
                stmt (.createStatement conn)]
      (if (.execute stmt sql)
        (let [rs (.getResultSet stmt)
              md (.getMetaData rs)
              col-count (.getColumnCount md)]
          (loop [rows []]
            (if (.next rs)
              (recur (conj rows (mapv #(.getObject rs (inc %)) (range col-count))))
              rows)))
        "no result set returned"))))
2026-04-24 10:57:50,515 WARN javacc.ClickHouseSqlParser :: Parse error at line 1, column 16.  Encountered: t. If you believe the SQL is valid, please feel free to open an issue on Github with this warning and the following SQL attached.
WITH RECURSIVE t AS ( SELECT 1 AS n UNION ALL SELECT n + 1 FROM t WHERE n < 3 ) SELECT * FROM t; 
"no result set returned"

Expected Behaviour

It returns [[1] [2] [3]]. The last version this worked in was 0.8.5

Environment

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

ClickHouse Server

  • ClickHouse Server version:
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions