Delete a row
Tables with the Data API are currently in public preview. Development is ongoing, and the features and functionality are subject to change. Astra DB Serverless, and the use of such, is subject to the DataStax Preview Terms. |
Finds a single row in a table using filter and sort clauses, and then deletes that row.
For general information about working with tables and rows, see About tables with the Data API.
Method signature
-
Python
-
TypeScript
-
Java
-
curl
The following method belongs to the astrapy.Table
class.
delete_one(
filter: Dict[str, Any],
*,
general_method_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> None
The following method belongs to the Table
class.
async deleteOne(
filter: TableFilter<Schema>,
options?: {
timeout?: number | TimeoutDescriptor,
},
): void
The following methods belong to the com.datastax.astra.client.tables.Table
class.
void deleteOne(Filter filter)
void deleteOne(
Filter filter,
TableDeleteOneOptions options
)
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_TABLE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"deleteOne": {
"filter": FILTER,
}
}'
Result
-
Python
-
TypeScript
-
Java
-
curl
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.
Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Returns a promise that resolves once the operation completes.
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.
Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Always returns a status.deletedCount
of -1
, regardless of whether a row was found and deleted.
Example response:
{
"status": {
"deletedCount": -1
}
}
Parameters
-
Python
-
TypeScript
-
Java
-
curl
Name | Type | Summary |
---|---|---|
|
|
Describes the full primary key of the row. The row matching that primary key will be deleted. Only the the |
|
|
A timeout, in milliseconds, to impose on the underlying API request. If not provided, the Table defaults apply. This parameter is aliased as |
Name | Type | Summary |
---|---|---|
|
|
Describes the full primary key of the row. The row matching that primary key will be deleted. Only the the |
|
|
The client-side timeout for this operation. |
Name | Type | Summary |
---|---|---|
|
Describes the row to delete by its primary key values. You cannot filter on non-primary keys. Only the the Filters can be instantiated with its constructor and specialized with method |
|
|
Operations to be applied to the delete operation like (mostly) timeout. |
Name | Type | Summary |
---|---|---|
|
|
The Data API command to find and delete the first row in a table that matches the given |
|
|
Key-value pairs describing the full primary key of the row to delete. Only the the |
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.
-
Python
-
TypeScript
-
Java
-
curl
from astrapy import DataAPIClient
# Get an existing table
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")
table = database.get_table("TABLE_NAME")
# Delete a row
table.delete_one(
{
"title": "Hidden Shadows of the Past",
"author": "John Anthony"
}
)
import { DataAPIClient } from '@datastax/astra-db-ts';
// Get an existing table
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');
const table = database.table('TABLE_NAME');
// Delete a row
(async function () {
const result = await table.deleteOne(
{
title: "Hidden Shadows of the Past",
author: "John Anthony"
}
);
console.log(result);
})();
package com.example;
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.definition.rows.Row;
import com.datastax.astra.client.tables.Table;
public class DeleteOne {
public static void main(String[] args) {
// Get an existing table
Table<Row> table = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
.getDatabase("ASTRA_DB_API_ENDPOINT")
.getTable("TABLE_NAME");
// Delete a row
Filter filter = new Filter(Map.of(
"title", "Hidden Shadows of the Past",
"author", "John Anthony"));
table.deleteOne(filter);
}
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_TABLE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"deleteOne": {
"filter": {
"title": "Hidden Shadows of the Past",
"author": "John Anthony"
}
}
}'
Client reference
-
Python
-
TypeScript
-
Java
-
curl
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
Client reference documentation is not applicable for HTTP.