Bird
0
0

You created a view with:

medium📝 Debug Q14 of 15
PostgreSQL - Views and Materialized Views
You created a view with:
CREATE VIEW recent_sales AS SELECT * FROM sales WHERE sale_date > CURRENT_DATE - INTERVAL '7 days';

But running SELECT * FROM recent_sales; returns an error. What is the likely cause?
ACURRENT_DATE cannot be used in a view definition
BThe view definition is correct; error is elsewhere
CThe view needs to be refreshed manually to update data
DThe INTERVAL syntax is invalid in the view definition
Step-by-Step Solution
Solution:
  1. Step 1: Check if INTERVAL and CURRENT_DATE are valid

    Both INTERVAL and CURRENT_DATE are valid in PostgreSQL and can be used in views.
  2. Step 2: Understand view behavior

    Views are virtual and always reflect current data; no manual refresh needed.
  3. Final Answer:

    The view definition is correct; error is elsewhere -> Option B
  4. Quick Check:

    Valid syntax means error is not in view code = A [OK]
Quick Trick: Check error source; valid syntax means problem is outside view [OK]
Common Mistakes:
  • Assuming CURRENT_DATE is disallowed in views
  • Thinking views store data needing refresh
  • Blaming INTERVAL syntax without checking error message

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes