All Products
Search
Document Center

Tablestore:Update a row

Last Updated:Aug 05, 2026

Use Tablestore SDK for Java to add, modify, or delete attribute columns in a row identified by its complete primary key.

Prerequisites

Install the Tablestore SDK for Java and initialize the client.

Description

Call updateRow to update a row identified by its complete primary key. You can add or modify attribute columns, delete a specified or all versions of a column, and use atomic counters.

public UpdateRowResponse updateRow(UpdateRowRequest updateRowRequest) throws TableStoreException, ClientException

The following example updates row row1 in the update_row_demo data table, setting attribute column col1 to changed_val1.

String tableName = "update_row_demo";

PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
primaryKeyBuilder.addPrimaryKeyColumn("id", PrimaryKeyValue.fromString("row1"));
PrimaryKey primaryKey = primaryKeyBuilder.build();

RowUpdateChange rowUpdateChange = new RowUpdateChange(tableName, primaryKey);
rowUpdateChange.put("col1", ColumnValue.fromString("changed_val1"));

client.updateRow(new UpdateRowRequest(rowUpdateChange));

Parameters

UpdateRowRequest contains the following parameters.

Name

Type

Description

rowChange (required)

RowUpdateChange

The configurations for updating a row.

transactionId (optional)

String

The local transaction ID. Set this parameter only when you update data in a local transaction.

For information about how to obtain and use the ID, see Use local transactions.

Row change

rowChange is of the RowUpdateChange type and contains the following parameters.

Name

Type

Description

tableName (required)

String

The name of the table.

primaryKey (required)

PrimaryKey

The primary key of the row. Specify all primary key columns in the same order and with the same types as the table schema. Primary key columns support the STRING, INTEGER, and BINARY types.

columnsToUpdate (required)

List<Pair<Column, RowUpdateChange.Type>>

The attribute column changes. Call put, deleteColumn, deleteColumns, or increment to add a change.

condition (optional)

Condition

The update condition. By default, Tablestore does not check whether the row exists.

For information about how to configure the condition, see Use conditional updates.

returnType (optional)

ReturnType

The return type. The default value is RT_NONE. For atomic counters, set this parameter to RT_AFTER_MODIFY to return the updated column values.

For information about how to configure atomic counters, see Use atomic counters.

returnColumnNames (optional)

Set<String>

The attribute columns whose updated values you want to return. This parameter applies only to atomic counters.

Attribute column change methods

Call the following methods to add changes to columnsToUpdate.

  • put: Adds an attribute column or writes a new version. You can specify the data version number.

  • deleteColumn: Deletes a specified version of an attribute column.

  • deleteColumns: Deletes all versions of an attribute column.

  • increment: Atomically increments an attribute column of the INTEGER type.

Response

UpdateRowResponse contains the following operation-specific field.

Field

Type

Description

row

Row

The updated attribute columns, obtained by calling getRow. This field is returned only when returnType is set to RT_AFTER_MODIFY.

Scenarios

Write attribute columns with a specified version number

Pass a third argument to put to specify the version number (a millisecond timestamp) for the attribute column. Use this approach to archive historical values keyed to business time.

String tableName = "update_row_demo";

PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
primaryKeyBuilder.addPrimaryKeyColumn("id", PrimaryKeyValue.fromString("row1"));
PrimaryKey primaryKey = primaryKeyBuilder.build();

RowUpdateChange rowUpdateChange = new RowUpdateChange(tableName, primaryKey);
// Specify the version number (a millisecond timestamp) as the third argument.
long version = System.currentTimeMillis();
rowUpdateChange.put("col2", ColumnValue.fromString("val2"), version);

client.updateRow(new UpdateRowRequest(rowUpdateChange));

Delete a specified version of an attribute column

Use deleteColumn to remove a single version of an attribute column while keeping all other versions intact.

String tableName = "update_row_demo";

PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
primaryKeyBuilder.addPrimaryKeyColumn("id", PrimaryKeyValue.fromString("row1"));
PrimaryKey primaryKey = primaryKeyBuilder.build();

RowUpdateChange rowUpdateChange = new RowUpdateChange(tableName, primaryKey);
// Delete the col2 value at the specified version (a millisecond timestamp).
rowUpdateChange.deleteColumn("col2", 1747893563831L);

client.updateRow(new UpdateRowRequest(rowUpdateChange));

Delete an entire attribute column

Use deleteColumns to delete every version of an attribute column in a single operation.

String tableName = "update_row_demo";

PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
primaryKeyBuilder.addPrimaryKeyColumn("id", PrimaryKeyValue.fromString("row1"));
PrimaryKey primaryKey = primaryKeyBuilder.build();

RowUpdateChange rowUpdateChange = new RowUpdateChange(tableName, primaryKey);
// Delete all versions of the col2 attribute column.
rowUpdateChange.deleteColumns("col2");

client.updateRow(new UpdateRowRequest(rowUpdateChange));