PG
PRO
428C9ERRORTier 2 — Caution✅ HIGH confidence

generated always

Category: Syntax Error or Access Rule ViolationVersions: Postgres 12+

What this means

SQLSTATE 428C9 is raised when an INSERT or UPDATE explicitly provides a value for a column defined as GENERATED ALWAYS AS IDENTITY or GENERATED ALWAYS AS (expression). These columns are managed entirely by Postgres and cannot be set by the user.

Why it happens

  1. 1INSERT provides a value for a GENERATED ALWAYS AS IDENTITY column
  2. 2UPDATE sets a value on a GENERATED ALWAYS computed column

How to reproduce

INSERT providing a value for a GENERATED ALWAYS identity column.

trigger — this will ERROR
CREATE TABLE orders (
  id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  total NUMERIC
);
INSERT INTO orders (id, total) VALUES (999, 100.00); -- 428C9
ERROR: cannot insert a non-DEFAULT value into column "id" DETAIL: Column "id" is an identity column defined as GENERATED ALWAYS.

Fix 1: Omit the generated column from the INSERT column list

When inserting into a table with GENERATED ALWAYS AS IDENTITY.

fix
INSERT INTO orders (total) VALUES (100.00); -- id generated automatically

Why this works

Omitting the identity column from the INSERT list lets Postgres generate the value automatically.

Fix 2: Use OVERRIDING SYSTEM VALUE if you must supply an identity value

During data migration where specific identity values must be preserved.

fix
INSERT INTO orders (id, total) OVERRIDING SYSTEM VALUE
VALUES (999, 100.00);

Why this works

OVERRIDING SYSTEM VALUE explicitly bypasses the GENERATED ALWAYS restriction, permitting a user-supplied value. Use only for data migration.

Fix 3: Use GENERATED BY DEFAULT AS IDENTITY instead for more flexibility

When the column should allow user-supplied values in some cases.

fix
ALTER TABLE orders ALTER COLUMN id
  SET GENERATED BY DEFAULT;

Why this works

BY DEFAULT allows user-supplied values without requiring OVERRIDING SYSTEM VALUE.

Version notes

Postgres 10+GENERATED AS IDENTITY introduced in Postgres 10. GENERATED ALWAYS AS (expression) computed columns added in Postgres 12.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

📚 Feature docs: https://www.postgresql.org/docs/current/ddl-identity-columns.html

🔧 Source ref: Class 42 — Syntax Error or Access Rule Violation

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE for GENERATED ALWAYS violations. Stable since Postgres 10.

See also

📄 Reference pages

GENERATED AS IDENTITYIdentity ColumnsOVERRIDING SYSTEM VALUE
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →