After creating a table in your keyspace, you can add columns to your tabledefinition.
Use the link:_attachments/restv2.html#operation/addColumn[Add a column definition] endpoint toreplace a column definition in the table you created.
Add a column with a simple data type
If you need to add an attribute to something you are storing in a table, youcan add a column by sending a POST request that specifies the column nameand data type in the --data (shortcut -d ).
Change a column name or data type
To change the name or data type of an existing column, use a similar command, butsend a PUT request instead:
Notice that the request changes the column name firstname to first by specifying thenew name and that the data type is still required.
Collections (set, list, map)
Collections can be defined when tables are created or added later.Recall that collections can be defined as frozen, meaning that the entirecollection must be retrieved, rather than a part of the collection.
See this CQL document to learn more about the keywordfrozenand its uses.
To add a set to a table, specify the data type set along with the data type of theset contents, such as text :
If the set were defined as a frozen set, specify "typeDefinition": "frozen<set<text>>" .
To add a list to a table, specify the data type list along with the data type of thelist contents, such as text .The difference between a set and a list is that a set is unordered, whereas a listis ordered:
To add a map to a table, specify the data type map along with the data type of themap key and the map value:
Tuple
To add a tuple to a table, specify the data type tuple along with the data type of theeach item in the tuple.A tuple can consist of two or more values that can be retrieved together.Tuples are frozen by default, and do not need to be specified with the keyword frozen .
User-defined type (UDT)
User-defined types (UDTs) are a useful feature that allows you to add a customdata type consisting of two or more associated attributes.UDTs must currently be created in Cassandra Query Language (CQL)or GraphQLbefore specifying for a column in a table definition with the REST API.Once the UDT exists in the keyspace as a resource, you can add a column thatspecifies the data type as udt .
First let's look at how to create a UDT with either CQL or GraphQL.
Now we can add a UDT column to our table:
To check if a column exists, execute aREST API query with cURL to find all the columns:
To get a particular column, specify the column in the URL: