Skip to content

Instantly share code, notes, and snippets.

@nara-l
Created June 22, 2018 14:40
Show Gist options
  • Save nara-l/0bc9e2cfa9f7a65bb2d75ce6d8014535 to your computer and use it in GitHub Desktop.
Save nara-l/0bc9e2cfa9f7a65bb2d75ce6d8014535 to your computer and use it in GitHub Desktop.
Resequencing Id's in Postgres
# 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