Skip to content

Instantly share code, notes, and snippets.

@cengizhancaliskan
Created March 12, 2021 10:00
Show Gist options
  • Save cengizhancaliskan/a80e17a4a80241cb1c0d92e40c89ec21 to your computer and use it in GitHub Desktop.
Save cengizhancaliskan/a80e17a4a80241cb1c0d92e40c89ec21 to your computer and use it in GitHub Desktop.
Postgresql restart id sequence identity
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