Database View

A database view is a saved query that behaves like a virtual table. In PostgreSQL’s words, “CREATE VIEW defines a view of a query. The view is not physically materialized. Instead, the query is run every time the view is referenced in a query.” A view therefore has no storage of its own; selecting from it re-runs the underlying SELECT statement against the base tables.

Views are used for abstraction, security, and simplification. They can hide a complex join or aggregation behind a simple name, so that callers query the view as if it were an ordinary table. They can also restrict access by exposing only certain columns or rows of the underlying tables, letting an application read a curated slice of the data without touching the originals. Some views are even updatable, and PostgreSQL supports a CHECK OPTION to ensure that inserts and updates through a view keep matching the view’s defining condition.

When re-running the query every time is too expensive, a materialized view caches the result. Unlike a plain view, a materialized view stores the query output physically and is refreshed on demand, trading freshness for speed.