Check table and column existence
To check if a table exists, execute a
REST API query with cURL
to find all the tables:
curl -s -L -X GET https://$ASTRA_CLUSTER_ID-$ASTRA_REGION.apps.astra.datastax.com/api/rest/v2/schemas/keyspaces/users_keyspace/tables \
-H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
{
"data": [
{
"name": "users",
"keyspace": "users_keyspace",
"columnDefinitions": [
{
"name": "firstname",
"typeDefinition": "varchar",
"static": false
},
{
"name": "lastname",
"typeDefinition": "varchar",
"static": false
},
{
"name": "email",
"typeDefinition": "varchar",
"static": false
},
{
"name": "favorite color",
"typeDefinition": "varchar",
"static": false
}
],
"primaryKey": {
"partitionKey": [
"firstname"
],
"clusteringKey": [
"lastname"
]
},
"tableOptions": {
"defaultTimeToLive": 0,
"clusteringExpression": [
{
"order": "Asc",
"column": "lastname"
}
]
}
}
]
}
In this case, we only have one table in the keyspace.
To get a particular table, specify the table in the URL:
curl -s -L \
-X GET https://$ASTRA_CLUSTER_ID-$ASTRA_REGION.apps.astra.datastax.com/api/rest/v2/schemas/keyspaces/users_keyspace/tables/users \
-H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json"
{
"data": {
"name": "users",
"keyspace": "users_keyspace",
"columnDefinitions": [
{
"name": "firstname",
"typeDefinition": "varchar",
"static": false
},
{
"name": "lastname",
"typeDefinition": "varchar",
"static": false
},
{
"name": "current_country",
"typeDefinition": "frozen<tuple<varchar, date, date>>",
"static": false
},
{
"name": "email",
"typeDefinition": "varchar",
"static": false
},
{
"name": "evaluations",
"typeDefinition": "map<int, varchar>",
"static": false
},
{
"name": "favorite color",
"typeDefinition": "varchar",
"static": false
},
{
"name": "favorite_books",
"typeDefinition": "set<varchar>",
"static": false
},
{
"name": "top_three_tv_shows",
"typeDefinition": "list<varchar>",
"static": false
}
],
"primaryKey": {
"partitionKey": [
"firstname"
],
"clusteringKey": [
"lastname"
]
},
"tableOptions": {
"defaultTimeToLive": 0,
"clusteringExpression": [
{
"order": "ASC",
"column": "lastname"
}
]
}
}
}
Although this command is slightly different, because we have only one table,
the command to get all tables and this command to just get the table users
return the same information.