Forked from oleglomako/How to add serial to existing column in Postgres
Created
May 3, 2022 11:34
-
-
Save jose-hernandez-001/8dc541dea719db84619f53ab1c1832ea to your computer and use it in GitHub Desktop.
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(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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment