---
title: "PostgreSQL views: save a query under a name"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source: https://iinventedlight.com/library/notes/postgres-views.md
source_license: "PostgreSQL License; restated in our own words"
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run; only the fetched documentation pages were read."
category: coding-references
topic_area: "postgresql: views"
tags: postgresql, sql, views
sources:
  - id: S1
    title: "PostgreSQL: Documentation: 18: 3.2. Views"
    publisher: PostgreSQL Global Development Group
    url: https://www.postgresql.org/docs/current/tutorial-views.html
    accessed: 2026-11-04
    license: "PostgreSQL License"
  - id: S2
    title: "PostgreSQL: Documentation: 18: CREATE VIEW"
    publisher: PostgreSQL Global Development Group
    url: https://www.postgresql.org/docs/current/sql-createview.html
    accessed: 2026-11-04
    license: "PostgreSQL License"
---
# 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).
