Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Last active June 16, 2020 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreymcmahon/1212bd1ad1795659c691fc052ef8280d to your computer and use it in GitHub Desktop.
Save coreymcmahon/1212bd1ad1795659c691fc052ef8280d to your computer and use it in GitHub Desktop.
Reset Postgres sequences
-- Get all relations from database
SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment