Bird
0
0

Given the materialized view mv_products created as CREATE MATERIALIZED VIEW mv_products AS SELECT id, price FROM products;, what will be the result of this query immediately after inserting a new product into products but before refreshing mv_products?

medium📝 query result Q13 of 15
PostgreSQL - Views and Materialized Views
Given the materialized view mv_products created as CREATE MATERIALIZED VIEW mv_products AS SELECT id, price FROM products;, what will be the result of this query immediately after inserting a new product into products but before refreshing mv_products?
SELECT * FROM mv_products WHERE id = 101;
AThe new product with id 101 will appear in the result
BThe materialized view will automatically refresh and show the new product
CQuery will cause a syntax error
DNo rows will be returned for id 101
Step-by-Step Solution
Solution:
  1. Step 1: Understand materialized view data update behavior

    Materialized views do not update automatically when base tables change. They require manual refresh.
  2. Step 2: Analyze query result after insert but before refresh

    The new product with id 101 is not yet in the materialized view, so the query returns no rows for id 101.
  3. Final Answer:

    No rows will be returned for id 101 -> Option D
  4. Quick Check:

    Materialized view data = stale until refresh [OK]
Quick Trick: Materialized views need manual refresh to show new data [OK]
Common Mistakes:
  • Assuming materialized views auto-update on insert
  • Expecting syntax error from a valid SELECT
  • Confusing materialized views with normal views

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes