Skip to content

Instantly share code, notes, and snippets.

@rcanepa
Created December 29, 2016 15:13
Show Gist options
  • Select an option

  • Save rcanepa/767dc85d2d1940cc4d976c6542b90286 to your computer and use it in GitHub Desktop.

Select an option

Save rcanepa/767dc85d2d1940cc4d976c6542b90286 to your computer and use it in GitHub Desktop.
PostgreSQL Enums
- 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