Bird
0
0

Given the following commands:

medium📝 query result Q13 of 15
PostgreSQL - Views and Materialized Views
Given the following commands:
CREATE TABLE products (id INT, price INT);
INSERT INTO products VALUES (1, 100), (2, 200);
CREATE MATERIALIZED VIEW cheap_products AS SELECT * FROM products WHERE price < 150;
SELECT * FROM cheap_products;

What will be the output of the SELECT query?
ARows with id=1 and price=100
BRows with id=2 and price=200
CNo rows returned
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the data and materialized view filter

    The table has two rows: (1,100) and (2,200). The materialized view selects rows where price < 150, so only (1,100) qualifies.
  2. Step 2: Query the materialized view

    Since the materialized view stores the filtered rows, selecting from it returns the row with id=1 and price=100.
  3. Final Answer:

    Rows with id=1 and price=100 -> Option A
  4. Quick Check:

    Filter price < 150 = row with id=1 [OK]
Quick Trick: Materialized view stores filtered rows, returns matching data [OK]
Common Mistakes:
  • Expecting all rows instead of filtered ones
  • Confusing materialized view with normal view behavior
  • Assuming syntax error due to multiple commands

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes