← All notes

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

Sources

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

Permanent ID: iil:note:cat5vfv1

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.},
}

Markdown

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.