All Products
Search
Document Center

Tablestore:Update a single row of data

Last Updated:Mar 11, 2026

Update attribute column values, add attribute columns, delete a specific version of an attribute column, or delete an entire attribute column in a Tablestore table by using the PHP SDK.

Before you begin

Initialize the Tablestore client

Method

public function updateRow(array $request)

Parameter description for $request

Name

Type

Description

table_name (required)

string

The name of the data table.

primary_key (required)

array

The primary key information, including primary key column names and values.

  • Primary key column data types include STRING, INTEGER, and BINARY.

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

update_of_attribute_columns (required)

array

The attribute columns to update and their operation types. Supported operation types: PUT (add or update a column value), DELETE (delete a specific version), and DELETE_ALL (delete an entire column).

condition (required)

array

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

return_content (optional)

array

The data to return.

  • return_type (required)array: The return type.

    • ReturnTypeConst::CONST_NONE (default): Returns no data.

    • ReturnTypeConst::CONST_PK: Returns the primary key columns.

    • ReturnTypeConst::CONST_AFTER_MODIFY: Returns the column values after modification. Use this option for atomic counters.

transaction_id (optional)

string

The local transaction ID. This ID uniquely identifies a local transaction. For more information, see local transactions.

Examples

The following example updates the row with the primary key value row1 in the test_table table. The attribute column col1 is set to changed_val1.

$request = array(
    'table_name' => 'test_table',
    // Build the primary key
    'primary_key' => array(
        array('id', 'row1')
    ),
    // Specify the update condition when updating a row.
    // RowExistenceExpectationConst::CONST_IGNORE means skip row existence checking.
    'condition' => RowExistenceExpectationConst::CONST_IGNORE
);
// Attribute columns to update
$request['update_of_attribute_columns'] = array(
    'PUT' => array(
        array('col1', 'changed_val1')
    )
);

try {
    // Call the updateRow method to update the row
    $response = $client->updateRow($request);
    echo "* Read CU Cost: " . $response['consumed']['capacity_unit']['read'] . "\n";
    echo "* Write CU Cost: " . $response['consumed']['capacity_unit']['write'] . "\n";   
} catch (Exception $e) {
    echo "Update Row failed.";
}

Use the following code snippets to perform other row update operations.

  • Add an attribute column.

    $request['update_of_attribute_columns'] = array(
        'PUT' => array(
            array('col2', 'val2')
        )
    );
  • Set the version number for an attribute column.

    $request['update_of_attribute_columns'] = array(
        'PUT' => array(
            array('col2', 'val2', null, intval(microtime(true) * 1000))
        )
    );
  • Delete a specific version of an attribute column.

    $request['update_of_attribute_columns'] = array(
        'DELETE' => array(
            array('col2', 1754285998447)
        )
    );
  • Delete all data in an attribute column.

    $request['update_of_attribute_columns'] = array(
        'DELETE_ALL' => array('col2')
    );

References

Batch update data