Bird
0
0

How do you correctly declare a recursive CTE named descendants in PostgreSQL?

easy📝 Syntax Q3 of 15
PostgreSQL - Common Table Expressions
How do you correctly declare a recursive CTE named descendants in PostgreSQL?
AWITH RECURSIVE descendants AS (SELECT * FROM table_name WHERE condition)
BWITH descendants RECURSIVE AS (SELECT * FROM table_name WHERE condition)
CWITH RECURSIVE AS descendants (SELECT * FROM table_name WHERE condition)
DRECURSIVE WITH descendants AS (SELECT * FROM table_name WHERE condition)
Step-by-Step Solution
Solution:
  1. Step 1: Use the WITH RECURSIVE clause

    This is the correct way to start a recursive CTE in PostgreSQL.
  2. Step 2: Name the CTE immediately after WITH RECURSIVE

    The CTE name descendants follows directly after.
  3. Step 3: Provide the CTE query inside parentheses

    The recursive query is enclosed in parentheses.
  4. Final Answer:

    WITH RECURSIVE descendants AS (SELECT * FROM table_name WHERE condition) -> Option A
  5. Quick Check:

    Check the order: WITH RECURSIVE <name> AS (…) [OK]
Quick Trick: Start with 'WITH RECURSIVE' followed by CTE name [OK]
Common Mistakes:
  • Placing RECURSIVE after the CTE name
  • Omitting the AS keyword
  • Incorrect order of WITH and RECURSIVE keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes