Bird
0
0

Consider this query:

medium📝 query result Q5 of 15
PostgreSQL - Common Table Expressions
Consider this query:
WITH cte AS NOT MATERIALIZED (SELECT generate_series(1,2) AS num) SELECT num FROM cte, generate_series(1,3) AS gs(n);

How many rows will the query return?
A6 rows
B2 rows
C3 rows
D1 row
Step-by-Step Solution
Solution:
  1. Step 1: Understand NOT MATERIALIZED CTE behavior

    NOT MATERIALIZED means the CTE is inlined and evaluated each time it appears.
  2. Step 2: Calculate cross join rows

    CTE generates 2 rows (1,2), generate_series generates 3 rows (1,2,3). Cross join produces 2*3=6 rows.
  3. Final Answer:

    6 rows -> Option A
  4. Quick Check:

    Non-materialized CTE cross join = product of rows [OK]
Quick Trick: Non-materialized CTE inlines; cross join multiplies rows [OK]
Common Mistakes:
  • Assuming fewer rows due to non-materialization
  • Confusing materialized and non-materialized effects
  • Counting only one side's rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes