SQLSTATE 42P10 ERROR Class 42: Syntax Error or Access Rule Violation

invalid_column_reference cannot use column reference in DEFAULT expression — 42P10

PostgreSQL error "cannot use column reference in DEFAULT expression" (SQLSTATE 42P10): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A DEFAULT expression referenced another column of the same table. Column defaults are evaluated without a row context, so they cannot read other columns. PostgreSQL raises SQLSTATE 42P10 (invalid_column_reference).

  • Triggered at CREATE TABLE/ALTER TABLE defining the default.
  • People often hit this trying to default one column from another.
  • Generated columns or triggers are the correct alternative.

What the server log shows

ERROR:  cannot use column reference in DEFAULT expression

Why PostgreSQL raises this — what the manual says

Section 5.2 Default Values:

“The default value can be an expression, which will be evaluated whenever the default value is inserted (not when the table is created).”

A column default is computed in isolation when no explicit value is supplied; at that moment the rest of the row is not available. Referencing another column is therefore disallowed and reported as 42P10.

Common causes

  • Trying to default a column to a value derived from a sibling column.
  • Porting a schema where another engine allowed inter-column defaults.

How to fix it

  1. Use a GENERATED column: total numeric GENERATED ALWAYS AS (qty * price) STORED.
  2. Compute the value in a BEFORE INSERT/UPDATE trigger.
  3. Set the value explicitly in the INSERT statement.

Related & next steps

Reference: PostgreSQL 18 Section 5.4 “Default Values”.

Was this helpful?