clause
WITH RECURSIVE
Allows a CTE to refer to its own result. A termination condition is essential. Example target: PostgreSQL 17 and SQLite (local fixture tested).
Formal Syntax & Structure
sql syntaxsql
WITH RECURSIVE name AS (anchor UNION ALL recursive_term) SELECT ...Working Example
Example Snippetsql
WITH RECURSIVE n(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM n WHERE x<3) SELECT x FROM n ORDER BY x;