Skip to content

Instantly share code, notes, and snippets.

@israelss
Last active September 16, 2022 21:04
Show Gist options
  • Save israelss/a73f941b40834c1775f57dfc1c5c0e12 to your computer and use it in GitHub Desktop.
Save israelss/a73f941b40834c1775f57dfc1c5c0e12 to your computer and use it in GitHub Desktop.
Reset and fill Postgres id sequence
-- Reset sequence to 1
ALTER SEQUENCE table_name_id_seq RESTART WITH 1;
-- Fill all entries with sequence
UPDATE table_name SET id=DEFAULT;
-- Ref: https://stackoverflow.com/questions/4678110/how-to-reset-sequence-in-postgres-and-fill-id-column-with-new-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment