Dark Mode

Retrieve data from your tables using Astra DB's REST API.

After creating a table in your keyspace and adding rows, you can retrieve data.Use the link:_attachments/restv2.html#operation/getRows[Get a row] endpoint toretrieve rows in the table you created.

Read data without WHERE clause

Data is most easily read using the primary key, supplied in the path to retrieve a row:

This method can only retrieve one row per call. Let's look at other calls thatcan retrieve more than one row at a time.

Operator options for reading with a WHERE clause

Most data retrieval uses a WHERE clause containing operators to designate a range of rows to return.

The operators available are:

  • eq (equal)
  • notEq (not equal) - limited use
  • gt (greater than)
  • gte (greater than or equal to)
  • lt (less than)
  • lte (less than or equal to)
  • in (within) - limited use
  • nin (not within) - limited use
  • contains (a map contains the specified value)
  • containsKey (a map contains the specified key)
  • containsEntry (a map contains the specified key:value pair)

The WHERE clause can use any of these operators, as applicable to the data type defined.The primary key of the table can be used in the WHERE clause, but non-primarykey columns cannot be used unless indexed.

Retrieve data using $in

Send a GET request to`/api/rest/v2/keyspaces/undefined/undefined?where=undefined to retrieve the two usersthat were entered using the $in` operator:

A query for table rows must include a primary key in the path or a WHERE clauseto retrieve a row.

Let's explore some of the other valid operators.

Send a GET request to /api/rest/v2/keyspaces/undefined/undefined to retrieve the row for Mookie using $eq :

The next query uses two operators, $eq and $contains in a multiple-part WHERE clause.

To query on the non-primary key, favorite_books in this case, anindexmust be created prior to executing the query.

Send a GET request to /api/rest/v2/keyspaces/undefined/undefined to retrieve the row for Janesha using $eq , and Emma using $contains :

Collections, tuples, and UDTs

Some data types require special handling to read the data.Examples of set , list , map , tuple , and udt are shown, using the columnschema created earlier.Because these columns are not part of the partition or clustering key, an indexis required to read the data.The indexes can be created withREST,GraphQL, orCQL.

Here are the indexes created for use in the following examples, in CQL:

SET:

Also, note the use of the fields parameter to retrieve only the values of the firstname and favorite_books .

LIST:

MAP:

TUPLE:

UDT: