cannot use subquery in DEFAULT expression

SQLSTATE 0A000 condition feature_not_supported class 0A — Feature Not Supported severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

A column DEFAULT expression contained a subquery. Default expressions cannot reference other tables, so PostgreSQL raises SQLSTATE 0A000 (feature_not_supported).

What the server log shows

ERROR:  cannot use subquery in DEFAULT expression

Why PostgreSQL raises this — what the manual says

As the CREATE TABLE reference (DEFAULT) explains:

A column DEFAULT expression must be evaluable for a single row in isolation, so it may not contain a subquery or reference other columns of the table; use a trigger or a generated column if the value must depend on a query result.

A column default must be a variable-free expression evaluated per row at insert time — it cannot run a query. A subquery would reference other rows/tables, which defaults forbid, so PostgreSQL reports 0A000.

Common causes

How to fix it

  1. Compute the value in the application or in the INSERT statement.
  2. Use a BEFORE INSERT trigger to populate the column from a lookup.
  3. Use a non-subquery expression (function call, constant, sequence) as the default.

Related & next steps

Reference: PostgreSQL 18 — CREATE TABLE.