Syntax
CREATE TYPE features:
- Schema-qualified names: Types can be defined in specific schemas
- ENUM types: User-defined enumeration types
- Empty enums (no values)
- Single-quoted string values
- Multiple values separated by commas
- Composite types: Row types with named attributes
- Multiple attributes with their data types
- Any valid PostgreSQL data type for attributes
- Named attributes for structured data
- Range types: Ranges over a subtype that has a btree operator class
- Built-in subtypes, and enums or domains defined in the same schema
subtype_opclassandcollationwhen they differ from the subtype’s defaultssubtype_diff, including a function created in the same migration (the range is created after it)canonical, which PostgreSQL only accepts as a C function, so it is dumped and compared but never created by pgschemamultirange_type_namewhen it differs from the default PostgreSQL derives (timerange→timemultirange,floatspan→floatspan_multirange)- The multirange and array types PostgreSQL creates alongside the range are part of it: they are not listed as types of their own, and columns may use them directly
Canonical Format
When generating migration SQL, pgschema produces types in the following canonical format:- Uses single-line format for empty enums
- Uses multi-line format with indentation for enums with values
- Each enum value is on its own indented line for readability
- No comma after the last enum value
- Composite types use single-line format with attributes separated by commas
- For DROP operations:
DROP TYPE IF EXISTS type_name RESTRICT; - ENUM types can be modified by adding values with
ALTER TYPE type_name ADD VALUE 'new_value' AFTER 'existing_value'; - Range types print
multirange_type_nameonly when it is not the default, andsubtype_opclass/collationonly when they are not the subtype’s defaults - PostgreSQL has no
ALTER TYPEfor a range’s definition, so a changed range is dropped and recreated (DROP TYPE ... RESTRICT;thenCREATE TYPE ... AS RANGE). TheDROPfails while a column, domain or composite attribute still uses the range or its multirange; change or drop that use in the same migration.

