---
title: "Generated column"
description: "A generated column is a table column whose value is automatically computed from an expression involving other columns, rather than being stored directly by INSERT or UPDATE statements."
canonical: "https://motherduck.com/glossary/generated-column/"
related:
  - title: "Data types | MotherDuck Docs"
    url: "https://motherduck.com/docs/sql-reference/duckdb-sql-reference/data-types/"
  - title: "More Than a Vibe: AI-Driven SQL That Actually Works | MotherDuck"
    url: "https://motherduck.com/videos/more-than-a-vibe-ai-driven-sql-that-actually-works/"
  - title: "EMBEDDING | MotherDuck Docs"
    url: "https://motherduck.com/docs/sql-reference/motherduck-sql-reference/ai-functions/embedding/"
---

# Generated column

> A generated column is a table column whose value is automatically computed from an expression involving other columns, rather than being stored directly by INSERT or UPDATE statements.

## Overview
A generated (or computed) column is defined by an expression instead of a plain data type, and its value is derived automatically from other columns in the same row. Applications cannot insert or update a generated column's value directly — the database computes it.

```sql
CREATE TABLE orders (
  quantity INTEGER,
  unit_price DECIMAL(10,2),
  total_price DECIMAL(10,2) GENERATED ALWAYS AS (quantity * unit_price)
);
```

Generated columns are useful for keeping derived values (totals, normalized text, extracted JSON fields) consistent and in sync with their source columns automatically, without relying on application code or triggers to recompute them.

<glossary-callout guide="duckdb-cheatsheet-full" />

## Virtual vs stored
SQL databases that support generated columns typically offer two flavors: **virtual** (computed on the fly whenever the column is read, not stored on disk) and **stored** (computed once and persisted to disk, refreshed whenever the source columns change, trading storage for read speed).

## DuckDB specifics
DuckDB supports generated columns with the syntax `column_name [type] GENERATED ALWAYS AS (expression) [VIRTUAL]`:

```sql
CREATE TABLE t1 (x FLOAT, two_x AS (2 * x));                              -- type inferred, virtual
CREATE TABLE t2 (x FLOAT, two_x FLOAT GENERATED ALWAYS AS (2 * x) VIRTUAL); -- fully explicit
```

As of the current DuckDB version, only the `VIRTUAL` variant is implemented — generated column values are computed from the expression each time the column is referenced, rather than being persisted to disk; `STORED` generated columns are not yet supported. A generated column's expression can reference other regular columns or even other generated columns defined earlier in the same table.