← All notes

PostgreSQL generated columns

Answer: A generated column is a special column that is always computed from other columns. (S1) You cannot write to it directly, and the expression must be immutable and refer only to the current row.

CREATE TABLE people (
  height_cm numeric,
  height_in numeric GENERATED ALWAYS AS (height_cm / 2.54) STORED
);
INSERT INTO people (height_cm) VALUES (180);

Rules

Stored vs virtual

| | Stored | Virtual | |---|---|---| | Computed | on write | on read |

Use VIRTUAL or STORED explicitly to make the choice clear.

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: 5.4. Generated Columns, PostgreSQL License; PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: CREATE TABLE, PostgreSQL License.

Cite this

Permanent ID: iil:note:j2e5vwks

iinventedlight. 2026. "PostgreSQL generated columns." iinventedlight Library, iil:note:j2e5vwks, version of 2026-11-04. https://iinventedlight.com/library/notes/postgres-generated-columns/. License: CC-BY-4.0.

@misc{iil_note_j2e5vwks,
  author = {{iinventedlight}},
  title = {{PostgreSQL generated columns}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/postgres-generated-columns/},
  note = {Permanent ID iil:note:j2e5vwks. 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-generated-columns.md.