Skip to content

Instantly share code, notes, and snippets.

@lbbedendo
Created October 19, 2023 17:57
Show Gist options
  • Save lbbedendo/54446caade2b50fda238aedc8213c3d7 to your computer and use it in GitHub Desktop.
Save lbbedendo/54446caade2b50fda238aedc8213c3d7 to your computer and use it in GitHub Desktop.
Update PostgreSQL sequence with max(id) + 1
SELECT setval(pg_get_serial_sequence('table_name', 'id'), coalesce(max(id),0) + 1, false) FROM table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment