0
0
PostgreSQLquery~10 mins

Materialized views concept in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a materialized view named 'sales_summary'.

PostgreSQL
CREATE MATERIALIZED VIEW sales_summary AS SELECT [1] FROM sales;
Drag options to blanks, or click blank then click option'
A*
BDISTINCT
CALL
DUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using DISTINCT or UNIQUE here will cause syntax errors in this context.
Forgetting to specify columns or using incorrect keywords.
2fill in blank
medium

Complete the code to refresh the materialized view 'sales_summary'.

PostgreSQL
REFRESH MATERIALIZED VIEW [1];
Drag options to blanks, or click blank then click option'
Asales_summary
Bsales
Csummary_sales
Dsales_view
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to refresh the base table instead of the materialized view.
Using a wrong or misspelled materialized view name.
3fill in blank
hard

Fix the error in the code to create a materialized view with a unique index.

PostgreSQL
CREATE MATERIALIZED VIEW sales_summary AS SELECT customer_id, SUM(amount) AS total FROM sales GROUP BY [1];
Drag options to blanks, or click blank then click option'
Aamount
Bsales_id
Ccustomer_id
Dtotal
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by the aggregated column total which is invalid.
Grouping by unrelated columns like amount or sales_id.
4fill in blank
hard

Fill both blanks to create a unique index on the materialized view 'sales_summary'.

PostgreSQL
CREATE UNIQUE INDEX [1] ON sales_summary([2]);
Drag options to blanks, or click blank then click option'
Asales_summary_idx
Bsales_idx
Ccustomer_id
Dtotal
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-unique column like total for the unique index.
Using an index name that does not relate to the materialized view.
5fill in blank
hard

Fill all three blanks to create and refresh a materialized view with data.

PostgreSQL
CREATE MATERIALIZED VIEW [1] AS SELECT [2] FROM sales WHERE amount [3] 100;
Drag options to blanks, or click blank then click option'
Ahigh_value_sales
B*
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > changes the filter logic.
Selecting specific columns instead of all columns when the task asks for all.