Created
June 27, 2019 20:09
-
-
Save maptastik/27dcbf7d9b265f2ae2855f0f35134c32 to your computer and use it in GitHub Desktop.
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
-- See https://stackoverflow.com/a/15748896/3163905 | |
-- Create a new sequence | |
CREATE sequence <column_id_seq>; | |
-- Alter the field you're converting to an auto-incrementing field be setting a default value based on a sequence | |
ALTER TABLE <table_name> alter <id_column> SET DEFAULT nextval(<'id_column_seq'>); | |
-- Set the current max value of the id column as the starting point for the sequence | |
SELECT setval(<'id_column_seq'>, <max_id_column_value> ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment