Bird
0
0

Consider this SQL:

medium📝 Debug Q14 of 15
PostgreSQL - Views and Materialized Views
Consider this SQL:
CREATE MATERIALIZED VIEW recent_orders AS SELECT * FROM orders WHERE order_date > CURRENT_DATE - INTERVAL '7 days';
REFRESH MATERIALIZED VIEW recent_orders;

Which of the following is a common mistake that would cause an error or unexpected behavior?
AUsing REFRESH MATERIALIZED VIEW without CONCURRENTLY
BCreating the materialized view without a SELECT statement
CNot refreshing the materialized view after data changes
DUsing CURRENT_DATE in the WHERE clause
Step-by-Step Solution
Solution:
  1. Step 1: Analyze each option for errors

    Not refreshing the materialized view after data changes causes stale data but no error. Using REFRESH MATERIALIZED VIEW without CONCURRENTLY is allowed but locks the view during refresh. Creating the materialized view without a SELECT statement is invalid syntax because materialized views require a SELECT query. Using CURRENT_DATE in the WHERE clause is valid usage.
  2. Step 2: Identify the syntax error

    Creating a materialized view without a SELECT statement causes a syntax error, so Creating the materialized view without a SELECT statement is the mistake causing error.
  3. Final Answer:

    Creating the materialized view without a SELECT statement -> Option B
  4. Quick Check:

    Materialized view requires SELECT query [OK]
Quick Trick: Materialized views must have a SELECT query [OK]
Common Mistakes:
  • Skipping the SELECT query in CREATE MATERIALIZED VIEW
  • Ignoring need to refresh after data changes
  • Assuming REFRESH must use CONCURRENTLY always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes