Forked from henriquemenezes/postgresql-set-id-seq.sql
Created
August 8, 2019 07:32
-
-
Save soiqualang/801df1f377815caf998051a3279c9b28 to your computer and use it in GitHub Desktop.
PostgreSQL set Next ID Sequence Value to MAX(id) from Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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