Use Tablestore SDK for Python to delete a row by primary key and optionally specify a delete condition or local transaction.
Prerequisites
Install the Tablestore SDK for Python and initialize a client.
Function description
Call delete_row to delete an entire row by primary key.
def delete_row(
self,
table_name,
row=None,
condition=None,
return_type=None,
transaction_id=None,
**kwargs,
)
The following example deletes the row whose primary key is ("device", 1) from example_table.
primary_key = [("partition", "device"), ("id", 1)]
row = Row(primary_key)
condition = Condition(RowExistenceExpectation.EXPECT_EXIST)
consumed, return_row = client.delete_row(
"example_table",
row,
condition,
)
print("Write CU: %s" % consumed.write)
Parameters
The delete_row method contains the following parameters.
|
Name |
Type |
Description |
|
table_name (required) |
|
The name of the table. |
|
row (required) |
|
The primary key of the row to delete. |
|
condition (optional) |
|
The delete condition. By default, row existence is not checked. For more information, see Use conditional updates. |
|
return_type (optional) |
|
The return type. |
|
transaction_id (optional) |
|
The local transaction ID. Specify this parameter only for deletes in a local transaction. For more information, see Use local transactions. |
Response
delete_row returns the following values.
|
Field |
Type |
Description |
|
consumed |
|
The read and write CUs consumed by the operation. |
|
return_row |
|
The returned row. If |