# Postgres Views

[Supabase](https://yomu.fyi/company/supabase) · Paul Copplestone · Nov 18, 2020

**Type:** Explainer

## Summary

Postgres views serve as query shortcuts that execute underlying SQL statements upon retrieval without generating new tables or persisting duplicate data. By encapsulating complex multi-table joins, standard views provide query consistency across applications, simplify repetitive calls, improve logical schema organization, and enhance security by restricting sensitive columns. In contrast, materialized views physically store query results on disk, dramatically reducing read latency for heavy queries spanning millions of rows. Because materialized views introduce the trade-off of stale data, administrators must periodically run the refresh command based on workload tolerances for use cases like analytics and internal dashboards. Materialized views should not substitute query optimization, as underlying query efficiency remains essential.

## Context

Complex, repetitive queries across multiple joined tables increase maintenance overhead, introduce risks of inconsistency across applications, and can suffer from slow execution times or sensitive data exposure.

## Approach / What changed

Encapsulating queries using standard Postgres views without storing data, or utilizing Postgres materialized views to physically persist query results alongside scheduled refresh operations.

## Takeaways

- Postgres views act as named query shortcuts that do not duplicate data, behaving like tables that can be joined or layered into new views while restricting access to sensitive columns.
- Materialized views physically store query results to accelerate read latency on large queries, but require executing REFRESH MATERIALIZED VIEW to manage data staleness.
- Materialized views suit workloads tolerant of outdated data, such as internal dashboards and analytics, but they do not replace the need to optimize slow underlying queries.

**Tags:** [Performance](https://yomu.fyi/topic/performance), [Postgres](https://yomu.fyi/topic/postgres)

[Read original post](https://supabase.com/blog/postgresql-views)
