Skip to content

Instantly share code, notes, and snippets.

@rtplv
Forked from scaryguy/change_id_column
Created July 5, 2020 11:45
Show Gist options
  • Save rtplv/040d48344ebfe847fceca877727261d9 to your computer and use it in GitHub Desktop.
Save rtplv/040d48344ebfe847fceca877727261d9 to your computer and use it in GitHub Desktop.
How to reset ID column of a PostgreSQL table to let auto incrementation begin from 1?
# See your sequence name inside psql console with \ds command.
ALTER SEQUENCE seq RESTART WITH 1;
# Update sequence
UPDATE table_name SET id=nextval('seq');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment