DROP TYPE

Immediately and irreversibly removes a UDT (user-defined type). The ability to drop a UDT that is defined in a table depends on whether the type is frozen or non-frozen.

Dropping a user-defined type that is in use by a table, an index, or another type is not supported. In this case, you must first drop the dependent objects before dropping the type.

See also: CREATE TYPE

Syntax

user_defined_type::= udt_name udt_name::= [ keyspace_name '.' ] identifier

drop_type_statement::= DROP TYPE [ IF EXISTS ] udt_name

DROP TYPE [ IF EXISTS ] [<keyspace_name>.]<type_name> ;
Syntax legend
Legend
Syntax conventions Description

UPPERCASE

Literal keyword.

Lowercase

Not literal.

< >

Variable value. Replace with a user-defined value.

[]

Optional. Square brackets ([]) surround optional command arguments. Do not type the square brackets.

( )

Group. Parentheses ( ( ) ) identify a group to choose from. Do not type the parentheses.

|

Or. A vertical bar (|) separates alternative elements. Type any one of the elements. Do not type the vertical bar.

...

Repeatable. An ellipsis ( ... ) indicates that you can repeat the syntax element as often as required.

'<Literal string>'

Single quotation (') marks must surround literal strings in CQL statements. Use single quotation marks to preserve upper case.

{ <key> : <value> }

Map collection. Braces ({ }) enclose map collections or key value pairs. A colon separates the key and the value.

<datatype2

Set, list, map, or tuple. Angle brackets ( < > ) enclose data types in a set, list, map, or tuple. Separate the data types with a comma.

<cql_statement>;

End CQL statement. A semicolon (;) terminates all CQL statements.

[--]

Separate the command line options from the command arguments with two hyphens ( -- ). This syntax is useful when arguments might be mistaken for command line options.

' <<schema\> ... </schema\>> '

Search CQL only: Single quotation marks (') surround an entire XML schema declaration.

@<xml_entity>='<xml_entity_type>'

Search CQL only: Identify the entity and literal value to overwrite the XML element in the schema and solrConfig files.

Parameters

Parameter Description Default

keyspace_name

Optional. Name of the keyspace that contains the table to index.

If no name is specified, the current keyspace is used.

type_name

Name of the type to drop.

Usage notes

There are several issues that may cause an error when attempting to drop a UDT:

  • If the UDT is used in a table, the UDT cannot be dropped until the table column is dropped.

InvalidRequest: Error from server: code=2200 [Invalid query]
message="Cannot drop user type cycling.basic_info as it is still
used by table cycling.cyclist_stats"
  • If the UDT is used in a column that has a secondary index, the UDT cannot be dropped until the index is dropped.

InvalidRequest: Error from server: code=2200 [Invalid query]
message="Cannot drop column races because it has dependent secondary indexes (cyclist_races_races_idx)"
  • If the UDT is used in a non-frozen column, the table column cannot be dropped with an ALTER TABLE command.

InvalidRequest: Error from server: code=2200 [Invalid query]
message="Cannot drop non-frozen column basics of user type basic_info"

Examples

The following ordered steps can be used to drop a UDT:

Drop a UDT that is used in a table:

  1. Drop an index that uses the type, if required.

    DROP INDEX IF EXISTS cycling.races_idx;
  2. Drop a table column that uses the type.

    ALTER TABLE cycling.cyclist_races
      DROP races;
  3. Drop the table that uses the type, if the first two steps do not work.

    DROP TABLE IF EXISTS cycling.cyclist_races;
  4. Drop the type.

    DROP TYPE IF EXISTS cycling.race;

Drop a UDT that is not used in a table:

  1. Drop the type.

    DROP TYPE IF EXISTS cycling.basic_info;

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