Skip to content
UniCircle
MediumConceptualViews

View vs materialized view

Question PG-VIW-009

What is the difference between a view and a materialized view in PostgreSQL? When would you use each?

Show the explanation

A view is a saved query. It stores no data; each time you select from it, PostgreSQL runs the underlying query, so results are always current. Simple views can even be updated.

A materialized view runs the query once and stores the result like a table. Reads are fast and it can have indexes, but the data is a snapshot until you refresh it.

SQL
create view active_students as
select id, name, branch from students where status = 'active';

create materialized view branch_stats as
select branch, count(*) as students, round(avg(cgpa), 2) as avg_cgpa
from students group by branch;

create unique index on branch_stats (branch);
refresh materialized view concurrently branch_stats;   -- readers are not blocked

Use a view to simplify or secure access to live data (hide columns, reuse joins). Use a materialized view for expensive aggregations, dashboards or reports where slightly stale data is acceptable. REFRESH … CONCURRENTLY needs a unique index on the materialized view; PostgreSQL does not refresh it automatically, so schedule it (for example with cron or pg_cron).

Original UniCircle question. Last reviewed 22 Oct 2026.