Created
June 22, 2018 14:40
-
-
Save nara-l/0bc9e2cfa9f7a65bb2d75ce6d8014535 to your computer and use it in GitHub Desktop.
Resequencing Id's in Postgres
This file contains hidden or 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
| # After an import of data sometimes when you try to create new records, postgres creates same ids and cause clashes from time to time | |
| # To correct the sequence and tell postgres where to start counting next run this | |
| SELECT pg_catalog.setval(pg_get_serial_sequence('table_name', 'id'), MAX(id)) FROM table_name; # replace table_name with required table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment