zed icon indicating copy to clipboard operation
zed copied to clipboard

SQL: Recursive CTEs

Open philrz opened this issue 7 months ago • 0 comments

While basic CTE functionality was added for SuperSQL in #5932, recursive CTEs are not yet supported, such as this simple example often used to explain the concept in SQL docs:

$ super -version
Version: 7f23f6560

$ super -c "WITH RECURSIVE counter(n) AS (
    SELECT 1            -- anchor member: start with 1
    UNION ALL
    SELECT n + 1        -- recursive member: increment
    FROM counter
    WHERE n < 5         -- stop condition
)
SELECT * FROM counter;"

parse error at line 1, column 23:
WITH RECURSIVE counter(n) AS (
                  === ^ ===

Details

At the time this issue is being opened, super is at commit 7f23f65. I started coming across recursive CTEs in my work with sqllogictests, such as this one. Several other complex recursive CTE queries are in that same file.

Here's Postgres providing the expected output on the example query shown at the top of this issue:

$ psql postgres
psql (17.5 (Homebrew))
Type "help" for help.

postgres=# WITH RECURSIVE counter(n) AS (
    SELECT 1            -- anchor member: start with 1
    UNION ALL
    SELECT n + 1        -- recursive member: increment
    FROM counter
    WHERE n < 5         -- stop condition
)
SELECT * FROM counter;
 n 
---
 1
 2
 3
 4
 5
(5 rows)

philrz avatar Jul 10 '25 21:07 philrz