Example: Generating sequences recursively
Notes on using recursive Common Table Expressions (CTEs):
WITH RECURSIVEmust contain a compoundSELECTUNION ALLperforms better thanUNION
— The WITH Clause, SQLite documentation
WITH RECURSIVE seq(n) AS (
VALUES(1) UNION ALL SELECT n + 1 FROM seq LIMIT 10
)
SELECT * FROM seq;
| n |
|---|
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |