Exclua uma única linha de uma tabela do Tablestore com o SDK para Python.
Pré-requisitos
Método
def delete_row(self, table_name, row=None, condition=None, return_type=None, transaction_id=None, **kwargs)
Exemplos
O exemplo a seguir exclui a linha com valor de chave primária row1 da tabela test_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)
Perguntas frequentes
Erro DeleteRow no SDK do Tablestore para Python 6.0.0
Para resolver esse problema:
Atualize o SDK do Tablestore para Python para a versão mais recente.
-
Modifique os parâmetros do método de exclusão.
# 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()))