Generate or traverse recursive data with `WITH RECURSIVE`.
Section: Querying, Joins, and Aggregation
Recursive CTE
sql
sql
WITH RECURSIVE nums(n) AS (
VALUES (1)
UNION ALL
SELECT n + 1 FROM nums WHERE n < 10
)
SELECT * FROM nums;Explanation
See summary for usage details.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Querying, Joins, and Aggregation