SupabasePaul CopplestoneExplainer
Postgres Views
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.
Source and freshness
- Source
- supabase.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.