Created
November 26, 2013 04:58
-
-
Save kevinkirkup/7653687 to your computer and use it in GitHub Desktop.
PostgreSQL AutoIncrement
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
CREATE SEQUENCE <field_seq>; | |
ALTER TABLE <table> | |
ALTER COLUMN <field> TYPE SMALLINT USING <field>::integer | |
, ALTER COLUMN <field> SET NOT NULL | |
, ALTER COLUMN <field> SET DEFAULT nextval('<field_seq>'); | |
ALTER SEQUENCE <field_seq> | |
OWNED BY <table>.<field>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment