Bird
0
0

What is wrong with this writable CTE query?

medium📝 Debug Q7 of 15
PostgreSQL - Common Table Expressions
What is wrong with this writable CTE query?

WITH deleted AS (DELETE FROM orders WHERE id = 10) SELECT * FROM deleted;
AMissing RETURNING clause in DELETE
BDELETE cannot be used in CTE
CSELECT * FROM deleted should be inside DELETE
DCTE name 'deleted' is a reserved keyword
Step-by-Step Solution
Solution:
  1. Step 1: Check DELETE inside writable CTE

    DELETE inside CTE must include RETURNING to output deleted rows.
  2. Step 2: Identify missing RETURNING

    Without RETURNING, the CTE returns no rows, causing an error or empty result.
  3. Final Answer:

    Missing RETURNING clause in DELETE -> Option A
  4. Quick Check:

    Writable CTE DELETE needs RETURNING [OK]
Quick Trick: Add RETURNING to DELETE in writable CTE [OK]
Common Mistakes:
  • Omitting RETURNING in DELETE
  • Thinking DELETE can't be in CTE
  • Misusing reserved words as CTE names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes