PostgreSQL views: save a query under a name
Short answer
CREATE VIEW name AS SELECT ... saves a query you can then select from like a table. A plain view stores no data; the query runs each time you use it. [S1][S2]
Why use views
They hide table structure behind a stable interface, so tables can change while queries keep working. [S1] Views can build on other views. [S1]
Options
CREATE OR REPLACE VIEW updates the definition; TEMP views vanish at session end. [S2] If you need stored results, look at materialized views instead.
Claims
- id: C1 claim: Views encapsulate table structure behind consistent interfaces. source: S1 evidence: "Views allow you to encapsulate the details of the structure of your tables"
- id: C2 claim: Building views on other views is common. source: S1 evidence: "Building views upon other views is not uncommon."
- id: C3 claim: A view is not materialized; its query runs on each reference. source: S2 evidence: "the query is run every time the view is referenced in a query"
- id: C4 claim: Temporary views are dropped at session end. source: S2 evidence: "Temporary views are automatically dropped at the end of the current session."
Sources
- [S1] PostgreSQL: Documentation: 18: 3.2. Views. PostgreSQL Global Development Group. https://www.postgresql.org/docs/current/tutorial-views.html . License: PostgreSQL License. Accessed 2026-11-04.
- [S2] PostgreSQL: Documentation: 18: CREATE VIEW. PostgreSQL Global Development Group. https://www.postgresql.org/docs/current/sql-createview.html . License: PostgreSQL License. Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: 3.2. Views, PostgreSQL License; PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: CREATE VIEW, PostgreSQL License.
Cite this
iinventedlight. 2026. "PostgreSQL views: save a query under a name." iinventedlight Library, iil:note:cat5vfv1, version of 2026-11-04. https://iinventedlight.com/library/notes/postgres-views/. License: CC-BY-4.0.
@misc{iil_note_cat5vfv1,
author = {{iinventedlight}},
title = {{PostgreSQL views: save a query under a name}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/postgres-views/},
note = {Permanent ID iil:note:cat5vfv1. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/postgres-views.md.