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 adds the field to the type.

    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 RENAME.
    ALTER TYPE cycling.fullname
    RENAME middlename TO middle
      AND lastname TO last
      AND firstname TO first;
    Verify the changes.
    DESC TYPE cycling.fullname;
    The renamed fields appear in the type definition.
    CREATE TYPE cycling.fullname (
        first text,
        last text,
        middle text
    );