Columns whose values are automatically computed from an expression over other columns in the same row. The database maintains the value rather than the application. Also called computed columns or virtual columns.
Columns whose values are computed from an expression, either stored on disk or computed on read. Useful for denormalization, materialized reports, and enforcing computed invariants at the schema level. PostgreSQL, MySQL, and SQL Server support them.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | 5.7 | Two modes: VIRTUAL (computed on read, no storage) and STORED (computed on write, stored on disk). VIRTUAL is the default. Generated columns cannot reference other generated columns, use subqueries, or call non-deterministic functions. Can be indexed only if STORED (or as a functional index in MySQL 8.0). |
| PostgreSQL | ✓ Supported | 12 | PostgreSQL 12 added GENERATED ALWAYS AS (...) STORED. Only STORED generated columns are supported — there is no VIRTUAL mode. The expression may reference other base columns but not other generated columns. Can be indexed normally. Prior to PG 12, use a trigger or a view to achieve similar results. |
| SQL Server | ✓ Supported | 2000 | Called computed columns. Two modes: PERSISTED (stored) and non-persisted (virtual). Syntax uses AS expression rather than GENERATED ALWAYS AS. Persisted computed columns can be indexed and included in foreign keys. Non-deterministic expressions are allowed in non-persisted columns but not in persisted ones. |
| Oracle | ✓ Supported | 11g | Called virtual columns. Syntax uses GENERATED ALWAYS AS (...) VIRTUAL. Only VIRTUAL mode (no STORED equivalent). Virtual columns cannot be stored physically but can be indexed (Oracle creates the index on the derived values). Cannot reference other virtual columns. |
| SQLite | ✓ Supported | 3.31.0 | Both VIRTUAL and STORED modes supported since 3.31.0 (2020-01-22). VIRTUAL is the default. Expression must be deterministic. Generated columns cannot be used as part of the PRIMARY KEY. Cannot be indexed unless STORED. |
Generated column terminology differs by engine: MySQL and PostgreSQL use GENERATED ALWAYS AS, SQL Server uses AS (computed column), Oracle uses VIRTUAL column. The STORED vs VIRTUAL split is roughly universal but PostgreSQL only supports STORED — there is no VIRTUAL mode. SQL Server's PERSISTED keyword maps to STORED. All engines allow indexing stored/persisted generated columns; only SQL Server and PostgreSQL allow indexing virtual/non-persisted ones as functional indexes. None allow referencing other generated columns in the expression.
Two modes: VIRTUAL (computed on read, no storage) and STORED (computed on write, stored on disk). VIRTUAL is the default. Generated columns cannot reference other generated columns, use subqueries, or call non-deterministic functions. Can be indexed only if STORED (or as a functional index in MySQL 8.0).
PostgreSQL 12 added GENERATED ALWAYS AS (...) STORED. Only STORED generated columns are supported — there is no VIRTUAL mode. The expression may reference other base columns but not other generated columns. Can be indexed normally. Prior to PG 12, use a trigger or a view to achieve similar results.
Called computed columns. Two modes: PERSISTED (stored) and non-persisted (virtual). Syntax uses AS expression rather than GENERATED ALWAYS AS. Persisted computed columns can be indexed and included in foreign keys. Non-deterministic expressions are allowed in non-persisted columns but not in persisted ones.
Called virtual columns. Syntax uses GENERATED ALWAYS AS (...) VIRTUAL. Only VIRTUAL mode (no STORED equivalent). Virtual columns cannot be stored physically but can be indexed (Oracle creates the index on the derived values). Cannot reference other virtual columns.
Both VIRTUAL and STORED modes supported since 3.31.0 (2020-01-22). VIRTUAL is the default. Expression must be deterministic. Generated columns cannot be used as part of the PRIMARY KEY. Cannot be indexed unless STORED.