Modifying a user-defined type (UDT)
Add or rename fields to a user-defined type (UDT) with the ALTER TYPE command.
Use the ALTER TYPE
command to add fields to a user-defined type
(UDT) or to rename an existing field in a UDT.
Restriction: Modifying UDTs used in primary keys or index columns is not
supported. Changing the field type is not supported.
Procedure
-
Add a middlename field of type text
to the user-defined type cycling.fullname.
ALTER TYPE cycling.fullname ADD middlename text;
The
ALTER TYPE
command creates the field metadata and adds the field to the type schema.To verify the changes, use theDESC TYPE
command.DESC TYPE cycling.fullname ;
Themiddlename
column appears in the type definition.CREATE TYPE cycling.fullname ( firstname text, lastname text, middlename text );
-
To change the name of an existing field, use the
RENAME
command.ALTER TYPE cycling.fullname RENAME middlename TO middleinitial;
Verify the change.DESC TYPE cycling.fullname ;
The changed field namemiddleinitial
appears in the type definition.CREATE TYPE cycling.fullname ( firstname text, lastname text, middleinitial text );