Bird
0
0

Given the table orders(order_id INT, amount INT) with data:

medium📝 query result Q4 of 15
PostgreSQL - Views and Materialized Views
Given the table orders(order_id INT, amount INT) with data:
order_id | amount
---------+--------
1        | 100
2        | 200
3        | 300
and the materialized view:
CREATE MATERIALIZED VIEW mv_total AS SELECT SUM(amount) AS total_amount FROM orders;

What will be the result of SELECT * FROM mv_total; immediately after creation?
Atotal_amount = 600
Btotal_amount = 0
CNo rows returned
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand materialized view stores query result

    At creation, the view stores the sum of amounts: 100 + 200 + 300 = 600.
  2. Step 2: Query the materialized view

    Selecting from the view returns the stored sum, which is 600.
  3. Final Answer:

    total_amount = 600 -> Option A
  4. Quick Check:

    Materialized view stores query result = 600 [OK]
Quick Trick: Materialized view stores snapshot of query result at creation [OK]
Common Mistakes:
  • Expecting zero or no rows
  • Confusing materialized view with empty table
  • Thinking query runs live on base table

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes