All Products
Search
Document Center

Tablestore:Update a single row of data

Last Updated:Jun 22, 2026

Use the PHP SDK to update attribute column values, add attribute columns, delete a specific version of an attribute column, or delete an entire attribute column in a Tablestore data table.

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 of the row, including column names and values.

  • Supported data types: STRING, INTEGER, and BINARY.

  • The number and types of primary keys must match the table schema.

update_of_attribute_columns (required)

array

The attribute columns to update. Supported operations: 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 ID of the local transaction. For more information, see local transactions.

Examples

The following example updates the row whose primary key value is row1 in the test_table table, setting the attribute column col1 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.";
}

You can also use the following snippets for other 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 versions of an attribute column.

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

References

Batch update data