Created
December 30, 2019 07:18
-
-
Save tenthree/b0dff6ccfe85fa0fce01fb74fe4822d1 to your computer and use it in GitHub Desktop.
alter an exist column to serial (auto increment)
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
-- PSQL | |
CREATE SEQUENCE {tableName}_{tableColumn}_seq; | |
ALTER SEQUENCE {tableName}_{tableColumn}_seq OWNED BY {tableName}.{tableColumn}; | |
ALTER TABLE {tableName} | |
ALTER COLUMN {tableColumn} SET DEFAULT nextval('{tableName}_{tableColumn}_seq'::regclass); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment