Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oleglomako/185df689706c5499612a0d54d3ffe856 to your computer and use it in GitHub Desktop.
Save oleglomako/185df689706c5499612a0d54d3ffe856 to your computer and use it in GitHub Desktop.
SELECT MAX(column_name) + 1 FROM table_name; -- for example max=999
CREATE SEQUENCE table_name_column_name_seq START WITH 999; -- replace 999 with max above
ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT nextval('table_name_column_name_seq');
@D-latali
Copy link

thanks man it work perfectely in postgresql 9.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment