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.
Tip: Use OpsCenter to view the CQL for a defined UDT in a keyspace.

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 the DESC TYPE command.
    DESC TYPE cycling.fullname ;
    The middlename 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 name middleinitial appears in the type definition.
    CREATE TYPE cycling.fullname (
        firstname text,
        lastname text,
        middleinitial text
    );