Skip to content

Instantly share code, notes, and snippets.

@tenthree
Created December 30, 2019 07:18
Show Gist options
  • Save tenthree/b0dff6ccfe85fa0fce01fb74fe4822d1 to your computer and use it in GitHub Desktop.
Save tenthree/b0dff6ccfe85fa0fce01fb74fe4822d1 to your computer and use it in GitHub Desktop.
alter an exist column to serial (auto increment)
-- 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