Last active
March 21, 2022 15:24
-
-
Save scaryguy/6239705 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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'); |
PostgreSQL:
Node script: Fix all tables identity: auto-increment / nextval, based on last inserted it.
https://gist.github.com/GarryOne/eabdb5704887c2d1cafd3cb1ebc7fb5e
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It does not work in Postgres 13