0
0
PostgreSQLquery~20 mins

REFRESH MATERIALIZED VIEW in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Materialized View Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the result of refreshing a materialized view?

Consider a materialized view sales_summary that aggregates sales data. After new sales are inserted into the base table, what will be the result of running REFRESH MATERIALIZED VIEW sales_summary;?

PostgreSQL
REFRESH MATERIALIZED VIEW sales_summary;
AThe materialized view is deleted and recreated from scratch, losing all previous data.
BThe materialized view data is updated to reflect the latest sales data from the base tables.
CThe materialized view remains unchanged until the database is restarted.
DThe materialized view is locked and cannot be queried until manually unlocked.
Attempts:
2 left
💡 Hint

Think about what a materialized view stores and what refreshing it means.

📝 Syntax
intermediate
1:30remaining
Which REFRESH MATERIALIZED VIEW syntax is correct?

Choose the correct syntax to refresh a materialized view named inventory_status in PostgreSQL.

AREFRESH MATERIALIZED VIEW inventory_status;
BREFRESH VIEW MATERIALIZED inventory_status;
CUPDATE MATERIALIZED VIEW inventory_status;
DREFRESH MATERIALIZED inventory_status VIEW;
Attempts:
2 left
💡 Hint

Remember the exact order of keywords in the command.

optimization
advanced
2:30remaining
How to refresh a materialized view without locking reads?

You want to refresh a materialized view daily_report but allow users to continue reading the old data during the refresh. Which option achieves this?

PostgreSQL
REFRESH MATERIALIZED VIEW CONCURRENTLY daily_report;
AREFRESH MATERIALIZED VIEW CONCURRENTLY daily_report;
BREFRESH MATERIALIZED VIEW daily_report WITH NO LOCK;
CREFRESH MATERIALIZED VIEW daily_report NOWAIT;
DREFRESH MATERIALIZED VIEW daily_report SKIP LOCK;
Attempts:
2 left
💡 Hint

Look for the keyword that allows concurrent reads during refresh.

🔧 Debug
advanced
2:30remaining
Why does REFRESH MATERIALIZED VIEW CONCURRENTLY fail with this error?

You run REFRESH MATERIALIZED VIEW CONCURRENTLY sales_data; but get the error: ERROR: materialized view must have a unique index to use CONCURRENTLY. What is the cause?

PostgreSQL
REFRESH MATERIALIZED VIEW CONCURRENTLY sales_data;
AThe materialized view is empty and cannot be refreshed concurrently.
BThe base tables of the materialized view are missing primary keys.
CThe materialized view <code>sales_data</code> does not have a unique index defined.
DThe database user lacks permission to refresh materialized views concurrently.
Attempts:
2 left
💡 Hint

Check the requirements for using CONCURRENTLY with materialized views.

🧠 Conceptual
expert
3:00remaining
What happens internally during REFRESH MATERIALIZED VIEW?

When you execute REFRESH MATERIALIZED VIEW, which of the following best describes what happens inside the database?

AThe database copies the materialized view data to a temporary table and merges changes asynchronously.
BThe database marks the materialized view as stale but does not update data until queried.
CThe database updates only the changed rows in the materialized view using incremental changes from the base tables.
DThe database reruns the query defining the materialized view and replaces the stored data with the new result set.
Attempts:
2 left
💡 Hint

Think about how materialized views store data and how refresh works.