Reset a Postgres sequence after a bulk import

Sql

Copying rows with explicit ids leaves the identity sequence behind, so the next insert collides with an existing row.

SELECT setval(pg_get_serial_sequence('users','id'), COALESCE(MAX(id),1)) FROM users;

More in Databases

Random picks