Bird
0
0

Given the table products(id, name, price) and the view CREATE VIEW cheap_products AS SELECT id, name FROM products WHERE price < 100; What happens if you try to update the name of a product through cheap_products view?

medium📝 query result Q13 of 15
PostgreSQL - Views and Materialized Views
Given the table products(id, name, price) and the view CREATE VIEW cheap_products AS SELECT id, name FROM products WHERE price < 100; What happens if you try to update the name of a product through cheap_products view?
AThe update changes only the view but not the underlying table
BThe update fails because the view filters rows with a WHERE clause
CThe update succeeds and changes the product name in the products table
DThe update causes a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand updatable views with WHERE clause

    Views that select from a single base table with a restricting WHERE clause are updatable in PostgreSQL.
  2. Step 2: Check the effect of updating through filtered view

    Updating the name of a product visible in the view (price < 100) will successfully update the underlying products table.
  3. Final Answer:

    The update succeeds and changes the product name in the products table -> Option C
  4. Quick Check:

    Single-table views with WHERE are updatable [OK]
Quick Trick: Single-table views with WHERE filters are updatable [OK]
Common Mistakes:
  • Thinking WHERE clause prevents updates
  • Thinking update affects only the view
  • Expecting syntax error instead of runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes