All Products
Search
Document Center

Tablestore:Delete a single row

Last Updated:Mar 31, 2026

Delete a single row of data from a Tablestore table by using the Python SDK.

Prerequisites

Initialize the Tablestore client

Method

def delete_row(self, table_name, row=None, condition=None, return_type=None, transaction_id=None, **kwargs)

Parameters

Parameter

Type

Description

table_name (required)

str

The name of the table.

row (required)

Row

The row to delete.

  • primary_key (Required)List[Tuple]: The information about the primary key, including the names of the primary key columns and their values.

    • Valid data types of primary key columns: STRING, INTEGER, and BINARY.

    • The number and types of primary key columns must match those defined for the table.

condition (optional)

Condition

The condition for deletion. For more information, see conditional update.

return_type (optional)

ReturnType

The return type.

  • RT_NONE (Default): No data is returned.

  • RT_PK: The primary key columns are returned.

transaction_id (optional)

str

The unique ID for the local transaction. For more information, see local transaction.

Sample code

The following sample code deletes a row whose primary key value is row1 from the test_table table.

try:
    # Construct the primary key.
    primary_key = [('id', 'row1')]

    # Construct the row to delete.
    row = Row(primary_key)

    # Call delete_row to delete the row.
    consumed, return_row = client.delete_row('test_table', row)
    print('Read CU Cost: %s' % consumed.read)
    print('Write CU Cost: %s' % consumed.write)
except Exception as e:
    print("Delete row failed with error: %s" % e)

FAQ

Error when deleting a single row by using the Tablestore Python SDK 6.0.0

Use one of the following solutions to resolve this issue:

  • Upgrade the Tablestore Python SDK to the latest version.

  • Modify the parameters of the delete method.

    # Set the table name.
    table_name = '<TABLE_NAME>'
    # Construct the primary key of the row.
    primary_key = [('gid', 1), ('uid', '101')]
    condition = Condition('IGNORE')
    try:
        consumed, return_row = client.delete_row(table_name, primary_key, condition)
        print('Deletion successful, consumed %s write CU.' % consumed.write)
    # Handle client exceptions, which are usually parameter errors or network issues.
    except OTSClientError as e:
        print("Delete row failed, http_status:%d, error_message:%s" % (e.get_http_status(), e.get_error_message()))
    # Handle server exceptions, which are usually parameter errors or throttling errors.
    except OTSServiceError as e:
        print("Delete row failed, http_status:%d, error_code:%s, error_message:%s, request_id:%s" % (
        e.get_http_status(), e.get_error_code(), e.get_error_message(), e.get_request_id()))

Related topics

Batch Update Data