Delete rows
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 rows in a table using filter clauses, and then deletes those rows.
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_many(
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 deleteMany(
filter: TableFilter<Schema>,
options?: {
timeout?: number | TimeoutDescriptor,
},
): void
The following methods belong to the com.datastax.astra.client.tables.Table
class.
void deleteMany(Filter filter)
void deleteMany(
Filter filter,
TableDeleteManyOptions 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 '{
"deleteMany": {
"filter": FILTER,
}
}'
Result
-
Python
-
TypeScript
-
Java
-
curl
Deletes rows that match the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Does not return anything.
Deletes rows that match 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 rows that match the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Does not return anything.
Deletes rows that match 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 | ||
---|---|---|---|---|
|
|
A filter dictionary to specify the rows to delete.
delete_many filter examplesFor example, if a table is partitioned by columns
Invalid filter examples:
For information about operators, see Filter operators for tables. |
||
|
|
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 | ||
---|---|---|---|---|
|
|
An object containing the filter to apply to the table to determine which rows to delete. It can be empty or contain key-value pairs that determine the rows to delete.
If not empty, the contents of
For information about operators, see Filter operators for tables. |
||
|
|
The client-side timeout for this operation. |
Name | Type | Summary |
---|---|---|
|
A filter expressing which condition the returned row must satisfy, which can be empty or use operators to compare columns with literal values.
Filters can be instantiated with its constructor and specialized with method If not empty, the contents of * For single-column primary keys, For information about operators, see Filter operators for tables. |
|
|
Operations to be applied to the delete operation like (mostly) timeout. |
Name | Type | Summary | ||
---|---|---|---|---|
|
|
The Data API command to delete any rows in a table that match a given |
||
|
|
Can be empty or contain key-value pairs that determine the rows to delete.
If not empty, the contents of
For information about operators, see Filter operators for tables. |
Examples
The following examples demonstrate how to delete rows in a table.
Delete a row by primary key
If the filter specifies the full primary key, only the row matching that full primary key is deleted.
In the following example, the table has a composite primary key with the columns title
and author
.
For more information, see Primary keys in tables and Filter operators for tables.
-
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 rows
table.delete_many(
{
"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 rows
(async function () {
const result = await table.deleteMany(
{
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.tables.definition.rows.Row;
import com.datastax.astra.client.tables.Table;
import java.util.Map;
public class DeleteMany {
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 rows
Filter filter = new Filter(Map.of(
"title", "Hidden Shadows of the Past",
"author", "John Anthony"));
table.deleteMany(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 '{
"deleteMany": {
"filter": {
"title": "Hidden Shadows of the Past",
"author": "John Anthony"
}
}
}'
Delete rows in a table with a single-column primary key
If the table has a single-column primary key, the filter must include the column in the primary key, and it cannot include any other columns.
In the following example, the table has a single-column primary key with the column title
.
For more information, see Primary keys in tables and Filter operators for tables.
-
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 rows
table.delete_many(
{
"title": "Hidden Shadows of the Past",
}
)
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 rows
(async function () {
const result = await table.deleteMany(
{
title: "Hidden Shadows of the Past",
}
);
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.tables.definition.rows.Row;
import com.datastax.astra.client.tables.Table;
import java.util.Map;
public class DeleteMany {
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 rows
Filter filter = new Filter(Map.of(
"title", "Hidden Shadows of the Past"));
table.deleteMany(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 '{
"deleteMany": {
"filter": {
"title": "Hidden Shadows of the Past"
}
}
}'
Delete rows in a table with a composite primary key
If the table has a composite primary key, the filter must include all columns in the primary key definition (all partition keys), and it cannot include any other columns.
In the following example, the table has a composite primary key with the columns title
and author
.
For more information, see Primary keys in tables and Filter operators for tables.
-
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 rows
table.delete_many(
{
"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 rows
(async function () {
const result = await table.deleteMany(
{
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.tables.definition.rows.Row;
import com.datastax.astra.client.tables.Table;
import java.util.Map;
public class DeleteMany {
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 rows
Filter filter = new Filter(Map.of(
"title", "Hidden Shadows of the Past",
"author", "John Anthony"));
table.deleteMany(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 '{
"deleteMany": {
"filter": {
"title": "Hidden Shadows of the Past",
"author": "John Anthony"
}
}
}'
Delete rows in a table with a compound primary key
If the table has a compound primary key, the filter must include all of the partition (grouping) columns in the primary key.
The filter can also include clustering (sorting) columns from the primary key:
-
The order of the clustering columns in the filter must match the order in the primary key definition. You can omit clustering keys, but you can’t skip any clustering keys. For example, if you have three clustering keys,
a
,b
, andc
, then you can includea
and omitb
andc
. However, if you includeb
, then you must also includea
. -
The last clustering column can use range operators (
$gt
,$gte
,$lt
, and$lte
) or the$eq
operator. All other clustering columns can only use the$eq
operator. For example, if your table has three clustering keys,a
,b
, andc
, then you can only use range operators withc
.
The filter cannot include any other columns.
In the following example, the table has a compound primary key with the partition column title
and the clustering column rating
.
For more information, see Primary keys in tables and Filter operators for tables.
-
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 rows
table.delete_many(
{
"title": "Hidden Shadows of the Past",
"rating": {"$gte": 4}
}
)
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 rows
(async function () {
const result = await table.deleteMany(
{
title: "Hidden Shadows of the Past",
rating: {$gte: 4}
}
);
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 DeleteMany {
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 rows
Filter filter = new Filter(Map.of(
"title", "Hidden Shadows of the Past",
"rating", Map.of("$gte",4))
);
table.deleteMany(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 '{
"deleteMany": {
"filter": {
"title": "Hidden Shadows of the Past",
"rating": {"$gte": 4}
}
}
}'
Delete all rows
To delete all rows, use an empty filter.
-
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 rows
table.delete_many({})
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 rows
(async function () {
const result = await table.deleteMany({});
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.tables.definition.rows.Row;
import com.datastax.astra.client.tables.Table;
public class DeleteMany {
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 rows
table.deleteMany(new 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 '{
"deleteMany": {
"filter": {}
}
}'
Similarly, an empty deleteMany
object deletes all rows.
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 '{
"deleteMany": {}
}'
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.