Change the definition of a data type.
ALTER TYPE name action [, ... ]
ALTER TYPE name OWNER TO new_owner
ALTER TYPE name RENAME ATTRIBUTE attribute_name TO new_attribute_name [ CASCADE | RESTRICT ]
ALTER TYPE name RENAME TO new_name
ALTER TYPE name SET SCHEMA new_schema
ALTER TYPE name ADD VALUE [ IF NOT EXISTS ] new_enum_value [ { BEFORE | AFTER } existing_enum_value ]
ALTER TYPE name SET DEFAULT ENCODING ( storage_directive )
where action is one of the following options:
ADD ATTRIBUTE attribute_name data_type [ COLLATE collation ] [ CASCADE | RESTRICT ]
DROP ATTRIBUTE [ IF EXISTS ] attribute_name [ CASCADE | RESTRICT ]
ALTER ATTRIBUTE attribute_name [ SET DATA ] TYPE data_type [ COLLATE collation ] [ CASCADE | RESTRICT ]
where storage_directive is:
COMPRESSTYPE={ZLIB | ZSTD | QUICKLZ | RLE_TYPE | NONE}
COMPRESSLEVEL={0-19}
BLOCKSIZE={8192-2097152}
ALTER TYPE Changes the definition of an existing type. There are several subforms:
The ADD ATTRIBUTE, DROP ATTRIBUTE, and ALTER ATTRIBUTE operations can be combined into multiple change lists to apply in parallel. For example, you can add multiple attributes and/or change the type of multiple attributes in a single command.
You can change the schema of names, owners, and types. You can also add or update storage options for scalar types.
Note: The YMatrix database does not support adding storage options for rows or composite types.
You must have this type to use ALTER TYPE. To change the type of schema, you must also have CREATE privileges for the new schema. To change the owner, you must also be a direct or indirect member of the newly owned role, and that role must have CREATE privileges for the schema of the type. (These restrictions force the change owner to not perform any actions of deleting and recreating the type. However, superusers can change ownership of any type.) To add or change the property type, you must also have privileges for the USAGE data type.
ALTER TYPE ... ADD VALUE (the form of adding a new value to the enum type) cannot be executed within a transaction block.
Comparisons involving increased enum values are sometimes slower than those involving only original members of the enum type. This usually only happens when you set the sort position of the new value (rather than the end of the list) using BEFORE or AFTER. However, sometimes even adding a new value to the end will happen (this happens if the OID counter is "wrapped" since the enum type was originally created). The growth rate is usually small. However, if it is important, you can get the best performance by deleting and recreating the enum type, or by dumping and reloading the database.
name
new_name
new_owner
new_schema
attribute_name
new_attribute_name
data_type
new_enum_value
existing_enum_value
storage_directive
To rename the data type named electronic_mail:
ALTER TYPE electronic_mail RENAME TO email;
Change the owner of the user-defined type email to joe:
ALTER TYPE email OWNER TO joe;
Change the mode of the user-defined type email to customers:
ALTER TYPE email SET SCHEMA customers;
Set or change the compression type and compression level of a user-defined type named int33:
ALTER TYPE int33 SET DEFAULT ENCODING (compresstype=zlib, compresslevel=7);
To add a new property to the type:
ALTER TYPE compfoo ADD ATTRIBUTE f3 int;
To add a new value to an enum type for a specific sorting location:
ALTER TYPE colors ADD VALUE 'orange' AFTER 'red';
Adding and removing variants of attributes is part of the SQL standard. The other variant is the YMatrix database extension.