ALTER TYPE
Modify a user-defined type. Apache Cassandra™ 2.1 and later.
Modify a user-defined type. Cassandra 2.1 and later.
Synopsis
ALTER TYPE field_name instruction
ALTER field_name TYPE new_type
| ADD field_name new_type
| RENAME field_name TO field_name
( AND field_name TO field_name ...
field_name is an arbitrary identifier for the field.
new_type is an identifier other than the reserved type names.
A semicolon that terminates CQL statements is not included in the synopsis. |
Description
- Change the type of an existing field.
- Append a new field to an existing type.
- Rename a field defined by the type.
First, after the ALTER TYPE keywords, specify the name of the user-defined type to be changed, followed by the type of change: ALTER, ADD, or RENAME. Next, provide the rest of the needed information, as explained in the following sections.
Changing the type of a field
To change the type of a field, the field must already exist in type definition and its type should be compatible with the new type. Consider the compatibility list before changing a data type. It is best to careful choose the data type for each column at the time of table creation.CREATE TYPE version (
model ascii,
version_number int
);
ALTER TYPE version ALTER model TYPE text;
ALTER TYPE version ALTER model TYPE blob;
Clustering column data types are very restricted in the options for alteration, because clustering column data is used to order rows in tables. Indexed columns cannot be altered.
Adding a field to a type
To add a new field to a type, use ALTER TYPE and the ADD keyword.
ALTER TYPE version ADD release_date timestamp;
To add a collection map field called point_release in this example that represents the release date and decimal designator, use this syntax:
ALTER TYPE version ADD point_release map<timestamp, decimal>;
Renaming a field of a type
ALTER TYPE version RENAME model TO sku;
ALTER TYPE version RENAME sku TO model AND version_number TO num