Created
December 29, 2016 15:13
-
-
Save rcanepa/767dc85d2d1940cc4d976c6542b90286 to your computer and use it in GitHub Desktop.
PostgreSQL Enums
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
| - To rename a data type: | |
| ALTER TYPE electronic_mail RENAME TO email; | |
| - To change the owner of the type email to joe: | |
| ALTER TYPE email OWNER TO joe; | |
| - To change the schema of the type email to customers: | |
| ALTER TYPE email SET SCHEMA customers; | |
| - To add a new attribute to a type: | |
| ALTER TYPE compfoo ADD ATTRIBUTE f3 int; | |
| - To add a new value to an enum type in a particular sort position: | |
| ALTER TYPE colors ADD VALUE 'orange' AFTER 'red'; | |
| - Fetch an enum values (as an array): | |
| SELECT enum_range(NULL::myenum) | |
| - Fetch an enum values (one value per record): | |
| SELECT unnest(enum_range(NULL::myenum)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment