Delete a row (Java)
Finds a single row in a table using filter clauses, and then deletes that row.
Deleting rows produces tombstones. Excessive tombstones can impact query performance.
For general information about working with tables and rows, see About tables with the Data API (Java).
|
Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart. |
Result
Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Does not return anything.
Signature
Use the deleteOne method, which belongs to the com.datastax.astra.client.tables.Table class.
void deleteOne(Filter filter)
void deleteOne(
Filter filter,
TableDeleteOneOptions options
)
Parameters
| Name | Type | Summary |
|---|---|---|
|
Describes the full primary key of the row to delete. For this method, the filter can only use the |
|
|
General API options for this operation, including the timeout. |
Examples
The following examples demonstrate how to delete a row in a table.
Delete a row by primary key
You can filter by primary key to find and delete a row. The filter must describe the full primary key and cannot include any other columns.
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
public class Example {
public static void main(String[] args) {
// Get an existing table
Table<Row> table =
new DataAPIClient("APPLICATION_TOKEN")
.getDatabase("API_ENDPOINT")
.getTable("TABLE_NAME");
// Delete a row
Filter filter =
Filters.and(
Filters.eq("title", "Hidden Shadows of the Past"),
Filters.eq("author", "John Anthony"));
table.deleteOne(filter);
}
}
Errors
Commands with a filter clause might return errors from the FILTER scope.
For a full list of Data API error codes and their corresponding messages, see Data API errors and error codes.
For more information about how the client handles underlying Data API errors, see Java client error handling.
Client reference
For more information, see the client reference.