SQLIntermediate#views

What is a view? What is a materialized view?

A view is a stored SELECT that behaves like a virtual table; it always reflects the current base data. A materialized view physically stores the result and must be refreshed.

Example
CREATE VIEW active_orders AS
  SELECT * FROM orders WHERE status = 'active';

CREATE MATERIALIZED VIEW monthly_sales AS
  SELECT DATE_TRUNC('month', order_date) m, SUM(total) FROM orders GROUP BY 1;

Related Questions

1
SQLIntermediate#transactions

Explain the ACID properties.

Open
2
SQLAdvanced#transactions

What are transaction isolation levels?

Open
3
SQLAdvanced#transactions

What is a deadlock and how do you avoid it?

Open