428C9ERRORTier 2 — Caution✅ HIGH confidencegenerated always
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
- 1INSERT provides a value for a GENERATED ALWAYS AS IDENTITY column
- 2UPDATE sets a value on a GENERATED ALWAYS computed column
How to reproduce
INSERT providing a value for a GENERATED ALWAYS identity column.
CREATE TABLE orders (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
total NUMERIC
);
INSERT INTO orders (id, total) VALUES (999, 100.00); -- 428C9Fix 1: Omit the generated column from the INSERT column list
When inserting into a table with GENERATED ALWAYS AS IDENTITY.
INSERT INTO orders (total) VALUES (100.00); -- id generated automaticallyWhy 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.
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.
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
🔗 Related errors
📄 Reference pages