-
-
Save cengizhancaliskan/a80e17a4a80241cb1c0d92e40c89ec21 to your computer and use it in GitHub Desktop.
Postgresql restart id sequence identity
This file contains hidden or 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
SELECT MAX(id) FROM "Content"; | |
SELECT nextval('"Content_id_seq"'::text); | |
BEGIN; | |
-- protect against concurrent inserts while you update the counter | |
LOCK TABLE "Content" IN EXCLUSIVE MODE; | |
-- Update the sequence | |
SELECT setval('"Content_id_seq"', COALESCE((SELECT MAX(id)+1 FROM "Content"), 1), false); | |
COMMIT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment