Bird
0
0

Identify the error in this recursive CTE:

medium📝 Debug Q6 of 15
PostgreSQL - Common Table Expressions
Identify the error in this recursive CTE:
WITH RECURSIVE cte AS ( SELECT id FROM nodes WHERE id = 1 UNION ALL SELECT id + 1 FROM cte WHERE id < 5 ) SELECT * FROM cte;
AAnchor member has no WHERE clause
BMissing UNION ALL keyword
CRecursive member increments id incorrectly
DThe recursive member references 'id' without table alias
Step-by-Step Solution
Solution:
  1. Step 1: Check recursive member references

    The recursive member uses 'id' but does not specify which table it comes from.
  2. Step 2: Identify missing alias

    It should reference 'cte.id' to avoid ambiguity.
  3. Final Answer:

    The recursive member references 'id' without table alias -> Option D
  4. Quick Check:

    Recursive member must alias columns from CTE [OK]
Quick Trick: Always alias recursive member columns from CTE [OK]
Common Mistakes:
  • Omitting table alias in recursive member
  • Confusing anchor and recursive members
  • Missing UNION ALL keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes