Alter a user-defined type (UDT)

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 are not supported. Changing the field type is not supported.

Add a user-defined data type (UDT)

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.

Check that the UDT is created

Verify the changes, use the DESC TYPE command:

DESCRIBE TYPE cycling.fullname;
Results

The middlename column appears in the type definition.

WARNING: cqlsh was built against 5.0-beta1, but this server is 5.0.  All features may not work!

CREATE TYPE cycling.fullname (
    firstname text,
    lastname text
);

Rename an existing UDT field

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;

Check the results

Verify the changes.

DESCRIBE TYPE cycling.fullname;
Results

The renamed fields appear in the type definition.

WARNING: cqlsh was built against 5.0-beta1, but this server is 5.0.  All features may not work!

CREATE TYPE cycling.fullname (
    firstname text,
    lastname text,
    middlename text
);

See also:

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com