PostgreSQL 17.12Lab-verified · 2026-11-30

PostgreSQL 428C9: cannot insert a non-DEFAULT value into column

You gave your own value to a column PostgreSQL always fills by itself (GENERATED ALWAYS identity or generated column).

PostgreSQL 17.12
428C9: cannot insert a non-DEFAULT value into column "id"

Jump to a cause

  1. 01INSERT with a value for a GENERATED ALWAYS identity column
  2. 02Copying rows with their old ids into a new identity table
  3. 03UPDATE of a GENERATED ALWAYS identity column
  4. 04INSERT into a generated (calculated) column

Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-11-30 · container image postgres:17

A column declared GENERATED ALWAYS AS IDENTITY takes its numbers only from its sequence, and a GENERATED ALWAYS AS (...) STORED column only from its expression. Writing your own value to either gives SQLSTATE 428C9. The DETAIL line tells you which kind of column it is.

Below are four common cases: an INSERT with id, copying rows with old ids, changing an id, and inserting into a calculated column.

01INSERT with a value for a GENERATED ALWAYS identity column

orders.id is GENERATED ALWAYS AS IDENTITY. INSERT INTO orders (id, amount) VALUES (2, 2000) failed; DETAIL says Column "id" is an identity column defined as GENERATED ALWAYS.

Leaving id out of the column list worked. PostgreSQL gave the new row id = 2.

Setup
Setuprun as lab_a
CREATE TABLE orders (id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, amount int);
INSERT INTO orders (amount) VALUES (1000);
OUTPUT
CREATE TABLE
INSERT 0 1
Reproducerun as lab_a
INSERT INTO orders (id, amount) VALUES (2, 2000);
✕ ERROR
ERROR:  428C9: cannot insert a non-DEFAULT value into column "id"
DETAIL:  Column "id" is an identity column defined as GENERATED ALWAYS.
HINT:  Use OVERRIDING SYSTEM VALUE to override.
Check the causerun as lab_a
SELECT column_name, is_identity, identity_generation FROM information_schema.columns WHERE table_name = 'orders' AND column_name = 'id';
OUTPUT
 column_name | is_identity | identity_generation
-------------+-------------+---------------------
 id          | YES         | ALWAYS
(1 row)

is_identity = YES and identity_generation = ALWAYS: the column does not accept your values. BY DEFAULT would.

Fixrun as lab_a
INSERT INTO orders (amount) VALUES (2000);
OUTPUT
INSERT 0 1
After the fixrun as lab_a
SELECT id, amount FROM orders ORDER BY id;
✓ SUCCESS
 id | amount
----+--------
  1 |   1000
  2 |   2000
(2 rows)

02Copying rows with their old ids into a new identity table

Moving data with INSERT INTO orders SELECT id, amount FROM orders_old failed, because the old ids (101, 102) are explicit values. The HINT says Use OVERRIDING SYSTEM VALUE to override.

INSERT INTO orders OVERRIDING SYSTEM VALUE SELECT ... copied both rows. The identity sequence does not move when you override it, so we set it to the highest id with setval(pg_get_serial_sequence('orders', 'id'), (SELECT max(id) FROM orders)). The next normal INSERT got id = 103.

Setup
Setuprun as lab_a
CREATE TABLE orders_old (id int PRIMARY KEY, amount int);
INSERT INTO orders_old VALUES (101, 1000), (102, 2000);
CREATE TABLE orders (id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, amount int);
OUTPUT
CREATE TABLE
INSERT 0 2
CREATE TABLE
Reproducerun as lab_a
INSERT INTO orders SELECT id, amount FROM orders_old;
✕ ERROR
ERROR:  428C9: cannot insert a non-DEFAULT value into column "id"
DETAIL:  Column "id" is an identity column defined as GENERATED ALWAYS.
HINT:  Use OVERRIDING SYSTEM VALUE to override.
Fixrun as lab_a
INSERT INTO orders OVERRIDING SYSTEM VALUE SELECT id, amount FROM orders_old;
SELECT setval(pg_get_serial_sequence('orders', 'id'), (SELECT max(id) FROM orders));
OUTPUT
INSERT 0 2
 setval
--------
    102
(1 row)
After the fixrun as lab_a
INSERT INTO orders (amount) VALUES (3000);
SELECT id, amount FROM orders ORDER BY id;
✓ SUCCESS
INSERT 0 1
 id  | amount
-----+--------
 101 |   1000
 102 |   2000
 103 |   3000
(3 rows)

03UPDATE of a GENERATED ALWAYS identity column

UPDATE orders SET id = 10 WHERE id = 1 failed with column "id" can only be updated to DEFAULT.

If the ids really must be editable, ALTER TABLE orders ALTER COLUMN id SET GENERATED BY DEFAULT changes the column. After that the same UPDATE worked (UPDATE 1), and the row became 10 | 1000.

Setup
Setuprun as lab_a
CREATE TABLE orders (id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, amount int);
INSERT INTO orders (amount) VALUES (1000), (2000);
OUTPUT
CREATE TABLE
INSERT 0 2
Reproducerun as lab_a
UPDATE orders SET id = 10 WHERE id = 1;
✕ ERROR
ERROR:  428C9: column "id" can only be updated to DEFAULT
DETAIL:  Column "id" is an identity column defined as GENERATED ALWAYS.
Fixrun as lab_a
ALTER TABLE orders ALTER COLUMN id SET GENERATED BY DEFAULT;
OUTPUT
ALTER TABLE
After the fixrun as lab_a
UPDATE orders SET id = 10 WHERE id = 1;
SELECT id, amount FROM orders ORDER BY id;
✓ SUCCESS
UPDATE 1
 id | amount
----+--------
  2 |   2000
 10 |   1000
(2 rows)

04INSERT into a generated (calculated) column

total is GENERATED ALWAYS AS (price * qty) STORED. Giving it a value in the INSERT failed; DETAIL says Column "total" is a generated column.

Inserting only id, price and qty worked, and total was calculated as 1500.

Setup
Setuprun as lab_a
CREATE TABLE order_items (id int PRIMARY KEY, price int, qty int,
  total int GENERATED ALWAYS AS (price * qty) STORED);
OUTPUT
CREATE TABLE
Reproducerun as lab_a
INSERT INTO order_items (id, price, qty, total) VALUES (1, 500, 3, 1500);
✕ ERROR
ERROR:  428C9: cannot insert a non-DEFAULT value into column "total"
DETAIL:  Column "total" is a generated column.
Fixrun as lab_a
INSERT INTO order_items (id, price, qty) VALUES (1, 500, 3);
OUTPUT
INSERT 0 1
After the fixrun as lab_a
SELECT id, price, qty, total FROM order_items;
✓ SUCCESS
 id | price | qty | total
----+-------+-----+-------
  1 |   500 |   3 |  1500
(1 row)

FAQ

How do I insert my own id into a GENERATED ALWAYS identity column?

Add OVERRIDING SYSTEM VALUE after the table name. The sequence does not move, so we also ran setval to the max id; the next normal INSERT then got 103.

What is the difference between GENERATED ALWAYS and BY DEFAULT?

ALWAYS rejects your values (428C9). After ALTER COLUMN id SET GENERATED BY DEFAULT, the UPDATE that failed here worked.

Why does INSERT ... SELECT fail when copying a table?

The SELECT passes the old ids into the identity column. Use OVERRIDING SYSTEM VALUE, or leave the id out of both lists so new ids are generated.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12