Atualize uma única linha em uma tabela de dados do Tablestore com o SDK para Python. Você pode atualizar, adicionar ou excluir colunas de atributo e versões específicas de colunas.
Pré-requisitos
Método
def update_row(self, table_name, row, condition, return_type=None, transaction_id=None)
Exemplos
Este exemplo atualiza uma linha na tabela test_table com chave primária row1 e define col1 como changed_val1.
try:
# Construct the primary key.
primary_key = [('id', 'row1')]
# Construct the attribute columns to update.
attribute_columns = {
'PUT': [('col1', 'changed_val1')]
}
# Construct the row to update.
row = Row(primary_key, attribute_columns)
# Call the update_row method to update the row.
# You must specify a condition to update a row.
# RowExistenceExpectation.IGNORE means the system does not check whether the row exists before the update.
consumed, return_row = client.update_row('test_table', row, Condition(RowExistenceExpectation.IGNORE))
print('Read CU Cost: %s' % consumed.read)
print('Write CU Cost: %s' % consumed.write)
except Exception as e:
print("Update row failed with error: %s" % e)
Outras operações com linhas:
-
Adicione uma coluna de atributo.
attribute_columns = { 'PUT': [('col2', 'val2')] } -
Defina o número de versão de uma coluna de atributo.
attribute_columns = { 'PUT': [('col2', 'val2', int(time.time() * 1000))] } -
Exclua uma versão específica de uma coluna de atributo.
attribute_columns = { 'DELETE': [('col2', None, 1747893563831)] } -
Exclua uma coluna de atributo inteira.
attribute_columns = { 'DELETE_ALL': ['col2'] }