Skip to content

fix: preserve recursive CTEs#11960

Open
nextchamp-saqib wants to merge 1 commit intoibis-project:mainfrom
nextchamp-saqib:with-recursive-fix
Open

fix: preserve recursive CTEs#11960
nextchamp-saqib wants to merge 1 commit intoibis-project:mainfrom
nextchamp-saqib:with-recursive-fix

Conversation

@nextchamp-saqib
Copy link
Copy Markdown
Contributor

Issue

In [1]: import ibis

In [2]: query = """WITH RECURSIVE numbers (n) AS (
   ...:     SELECT 1 AS n
   ...:     UNION ALL
   ...:     SELECT n + 1 FROM numbers WHERE n < 5
   ...: )
   ...: SELECT n FROM numbers;"""

In [3]: db = ibis.duckdb.connect()

In [4]: q = db.sql(query)

In [5]: ibis.to_sql(db.sql(query))
Out[5]: 
WITH numbers(n) AS (
  SELECT
    1 AS n
  UNION ALL
  SELECT
    n + 1
  FROM numbers
  WHERE
    n < 5
)
SELECT
  n
FROM numbers

After proposed fix

In [1]: import ibis

In [4]: ...

In [5]: ibis.to_sql(db.sql(query))
Out[5]: 
WITH RECURSIVE numbers(n) AS (
  SELECT
    1 AS n
  UNION ALL
  SELECT
    n + 1
  FROM numbers
  WHERE
    n < 5
)
SELECT
  n
FROM numbers

@github-actions github-actions bot added the sql Backends that generate SQL label Mar 3, 2026
@cpcloud
Copy link
Copy Markdown
Member

cpcloud commented Mar 25, 2026

This needs a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql Backends that generate SQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants