Bird
0
0

Given the query:

medium📝 query result Q13 of 15
PostgreSQL - Common Table Expressions
Given the query:
WITH cte AS MATERIALIZED (SELECT id FROM users WHERE active = true) SELECT * FROM cte WHERE id < 10;

What is the effect of MATERIALIZED here?
AThe CTE result is stored temporarily before filtering by <code>id < 10</code>
BThe CTE is inlined and filtered directly without storing
CThe query will produce a syntax error
DThe CTE is ignored and the main query runs alone
Step-by-Step Solution
Solution:
  1. Step 1: Understand MATERIALIZED effect on CTE

    Using MATERIALIZED forces PostgreSQL to store the CTE result before the outer query uses it.
  2. Step 2: Analyze query filtering

    The outer query filters the stored CTE result by id < 10, so filtering happens after storage.
  3. Final Answer:

    The CTE result is stored temporarily before filtering by id < 10 -> Option A
  4. Quick Check:

    MATERIALIZED = store then filter [OK]
Quick Trick: MATERIALIZED stores CTE before outer query filters [OK]
Common Mistakes:
  • Thinking filtering happens before storing
  • Assuming MATERIALIZED causes syntax error
  • Believing CTE is ignored

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes