Todos os produtos
Search
Central de documentação

Tablestore:Delete a single row

Última atualização: Jun 30, 2026

Exclua uma linha de uma tabela de dados do Tablestore com o SDK para Go.

Pré-requisitos

Inicializar o cliente do Tablestore

Método

func (tableStoreClient *TableStoreClient) DeleteRow(request *DeleteRowRequest) (*DeleteRowResponse, error)

DeleteRowRequest fields

  • DeleteRowChange (Required)*DeleteRowChange: Especifica a linha a excluir. Configure os seguintes campos:

    Name

    Type

    Description

    TableName (Required)

    string

    Nome da tabela que contém a linha.

    PrimaryKey (Required)

    PrimaryKey

    Chave primária da linha, com nome e valor para cada coluna de chave primária.

    • As colunas de chave primária aceitam os tipos STRING, INTEGER e BINARY.

    • A quantidade e os tipos de dados das colunas de chave primária devem corresponder ao esquema de chave primária da tabela.

    Condition (Required)

    RowCondition

    Condição avaliada antes da exclusão da linha. Para obter detalhes, consulte atualização condicional.

    TransactionId (Optional)

    string

    ID exclusivo da transação local. Para obter detalhes, consulte transação local.

Exemplo

O exemplo a seguir exclui a linha com valor de chave primária 'row1' da tabela 'test_table'.

func DeleteRowSample(client *tablestore.TableStoreClient) {
    // Build the primary key.
    deletePk := new(tablestore.PrimaryKey)
    deletePk.AddPrimaryKeyColumn("id", "row1")

    // Build the DeleteRowChange for the target row.
    deleteRowChange := new(tablestore.DeleteRowChange)
    deleteRowChange.TableName = "test_table"
    deleteRowChange.PrimaryKey = deletePk 
    // A delete condition is required. RowExistenceExpectation_IGNORE skips the row existence check.
    deleteRowChange.SetCondition(tablestore.RowExistenceExpectation_IGNORE)

    // Invoke DeleteRow to delete the row.
    deleteRowReq := new(tablestore.DeleteRowRequest)
    deleteRowReq.DeleteRowChange = deleteRowChange
    response, err := client.DeleteRow(deleteRowReq)
    if err != nil {
        fmt.Println("Delete row failed with error: ", err)
    } else {
        fmt.Printf("RequestId: %s \n", response.RequestId)
        fmt.Printf("Read CU Cost: %d \n", response.ConsumedCapacityUnit.Read)
        fmt.Printf("Write CU Cost: %d \n", response.ConsumedCapacityUnit.Write)
    }
}

Tópicos relacionados

Gravar dados em lote