Create a user-defined type (UDT)
A user-defined type, or UDT, consists of two or more values that can be retrieved together. UDTs are useful for associating items that are naturally grouped, like an address (street, city, zip code), or a review (item reviewed, rating, date reviewed).
UDTs are stored in a defined keyspace and can be used in other UDT definitions or table columns.
Send a POST
request to /api/rest/v2/schemas/keyspaces{keyspace_name}/types
.
In this example we use address_type
for the name
. The defined fields
describe
the included items and their data type.
curl -s -L -X POST https://$ASTRA_CLUSTER_ID-$ASTRA_REGION.apps.astra.datastax.com/api/rest/v2/schemas/keyspaces/users_keyspace/types \
-H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"name": "address_type",
"fields":[
{
"name": "street",
"typeDefinition": "text"
},
{
"name": "city",
"typeDefinition": "text"
},
{
"name": "state",
"typeDefinition": "text"
},
{
"name": "zip",
"typeDefinition": "text"
}
]
}'
{
"name": "address_type"
}