Skip to content

Instantly share code, notes, and snippets.

@tarkhil
Created January 25, 2024 07:55
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 tarkhil/9d1d13e64aeb5e0ebacf4c709c2e6cb3 to your computer and use it in GitHub Desktop.
Save tarkhil/9d1d13e64aeb5e0ebacf4c709c2e6cb3 to your computer and use it in GitHub Desktop.
Fix all sequences in postgres
-- Accidently, I've got and restored a dump without proper sequence values
SELECT concat('SELECT set', left(substr(column_default, 5),-1),', (select max(', column_name,') from ', table_schema, '.', table_name, ')+1);') FROM information_schema.columns where column_default like 'nextval%';
-- just save it into SQL and run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment