使用 Python SDK 按主鍵刪除單行資料,並按需設定刪除條件或局部事務。
前提條件
安裝Tablestore Python SDK並初始化用戶端。
功能說明
調用 delete_row 方法按主鍵刪除整行資料。
def delete_row(
self,
table_name,
row=None,
condition=None,
return_type=None,
transaction_id=None,
**kwargs,
)
以下樣本刪除 example_table 中主鍵為 ("device", 1) 的一行資料。
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)
參數說明
delete_row 方法包含以下參數。
|
名稱 |
類型 |
說明 |
|
table_name(必選) |
|
資料表名稱。 |
|
row(必選) |
|
待刪除行的主鍵。 |
|
condition(可選) |
|
刪除條件。預設不判斷行是否存在。有關配置方法,請參見條件更新。 |
|
return_type(可選) |
|
傳回型別。 |
|
transaction_id(可選) |
|
局部事務 ID。僅在局部事務內刪除資料時設定。有關使用方法,請參見局部事務。 |
傳回值
delete_row 返回以下值。
|
欄位 |
類型 |
說明 |
|
consumed |
|
本次操作消耗的讀寫 CU。 |
|
return_row |
|
返回的行資料。 |