Modifying a user-defined type
Adding columns to a user-defined type with the ALTER TYPE command.
Use the ALTER TYPE
command to add new fields to a user-defined type
or to rename an existing field.
Procedure
-
Add a middlename field of type text
to the user-defined type cycling.fullname.
ALTER TYPE cycling.fullname ADD middlename text;
This creates the field metadata and adds the field to the type schema.
To verify the changes, use DESC TYPE.DESC TYPE cycling.fullname ;
The middle name columns shows in the type definition.CREATE TYPE cycling.fullname ( firstname text, lastname text, middlename text );
-
To change the name of an existing field use
RENAME
.ALTER TYPE cycling.fullname RENAME middlename TO middleinitial;
DESC TYPE cycling.fullname ;
Shows the new name in the type definition.CREATE TYPE cycling.fullname ( firstname text, lastname text, middleinitial text );