Skip to content

Postgres offers two distinct types of views: standard views and materialized views. Standard views operate as virtual tables that reflect real-time data, whereas materialized views store query results physically and need periodic refreshes. The distinction matters for database performance and data integrity, so choose the type of view based on your requirements for data freshness and query performance.

What are standard views in PostgreSQL?

In Postgres, a standard view acts as a virtual table that always reflects the latest data. Every query against the view executes the underlying SQL statement in real time, which simplifies complex queries and keeps data consistent. To create a standard view:

CREATE VIEW example_view AS
SELECT column1, column2
FROM some_table
WHERE condition = true;

Choose standard views for scenarios requiring up-to-the-minute data without significantly impacting database performance.

What are materialized views in PostgreSQL?

Unlike standard views, materialized views in Postgres cache the query result as a physical table. This caching significantly speeds up complex queries because the database doesn’t need to re-execute the original SQL query on each access. You do have to refresh the view to update its data:

CREATE MATERIALIZED VIEW example_materialized_view AS
SELECT column1, column2
FROM some_table
WHERE condition = true;

To refresh this materialized view, use the following command:

REFRESH MATERIALIZED VIEW example_materialized_view;

Materialized views are ideal for complex, data-heavy queries where it’s acceptable for the information to be slightly outdated.

Choosing between standard and materialized views

Base your choice on your data access needs and query performance requirements:

  • Opt for standard views when you need immediate access to the most current data.
  • Choose materialized views for complex queries where improved performance outweighs the need for the latest data.

Picking the right view type for each case can make your Postgres database significantly more efficient.

Written by

Robert Cooper avatar

Robert Cooper

Senior Software Engineer

Robert Cooper is a senior engineer who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Basedash lets you build charts, dashboards, and reports in seconds using all your data.