PostgreSQL error code
PostgreSQL error 42P19
42P19 is the SQLSTATE PostgreSQL reports for invalid recursion, in class 42, Syntax Error or Access Rule Violation.
| SQLSTATE | 42P19 |
|---|---|
| Condition name | invalid_recursion |
| Class | 42 — Syntax Error or Access Rule Violation |
Reproduce it, then fix it
A recursive CTE has to start with its non-recursive part, then UNION, then the part that refers to itself. Here they’re the wrong way round. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
WITH RECURSIVE days(d) AS ( SELECT d + 1 FROM days WHERE d < 7 UNION ALL SELECT 1 ) SELECT d FROM days;
WITH RECURSIVE days(d) AS ( SELECT 1 UNION ALL SELECT d + 1 FROM days WHERE d < 7 ) SELECT d FROM days;