Updates the data of a row.

Note If the specified row does not exist, a new row is added. If the specified row exists, the values of the specified columns are added, modified, or deleted based on the request.

Request syntax

message UpdateRowRequest {
    required string table_name = 1;
    required bytes row_change = 2;
    required Condition condition = 3;
    optional ReturnContent return_content = 4; 
}
Parameter Type Required Description
table_name string Yes The name of the table whose data you want to update.
row_change bytes Yes Specifies the data that you use to update the row, including primary key columns and attribute columns. The data is encoded in the PlainBuffer format. For more information about PlainBuffer, see PlainBuffer.

All attribute columns whose data you want to update for this row. Tablestore adds, modifies, or deletes the values in the specified attribute columns based on the content of UpdateType in row_change. The columns that exist in this row but are not specified by row_change are not affected.

Valid values of UpdateType:

  • PUT: The value must be a valid attribute column value. If the specified column does not exist, a new column is added. If the specified column exists, the existing column is overwritten.
  • DELETE: The value must be empty, and a timestamp must be specified. This update type specifies that data of the specified version is deleted from the column.
  • DELETE_ALL: The value and the timestamp must be empty. This update type specifies that data of all versions in the column are deleted.
    Note A row exists even if all attribute columns in the row are deleted. To delete a row, call the DeleteRow operation.
condition Condition Yes Specifies whether to check the row existence before data is updated. Default value: IGNORE. Valid values:
  • IGNORE: The row existence is not checked. If you set the condition parameter to IGNORE, the operation is not affected regardless of whether the row exists.
  • EXPECT_EXIST: The row is expected to exist. If the row is expected to exist but the row does not exist, the row cannot be updated and an error is returned.
return_content ReturnContent No The type of data to return. Only the primary key can be returned. In most cases, this parameter is used by the auto-increment primary key column feature.

Response syntax

message UpdateRowResponse {
    required ConsumedCapacity consumed = 1;
    optional bytes row = 2;
}
Parameter Type Description
consumed ConsumedCapacity The number of capacity units (CUs) consumed by this request. For more information, see CU consumption.
row bytes The data that is returned when return_content is specified. If return_content is not specified or no value is returned, NULL is returned.

The returned data is encoded in the PlainBuffer format. For more information about PlainBuffer, see PlainBuffer.

Use Tablestore SDKs

You can use the following Tablestore SDKs to update a row of data:

CU consumption

  • If the row that you want to update does not exist, the number of consumed CUs varies based on the value that you specified for the condition parameter.
    • If the value of the condition parameter is IGNORE, the number of consumed write CUs is rounded up from the value that is calculated by using the following formula: Number of consumed write CUs = (Size of data in all primary key columns of the row + Size of data in attribute columns that you want to update)/4 KB. If UpdateRow contains an attribute column that you want to delete, the length of the column name is calculated as the size of data in the column.
    • If the value of the condition parameter is EXPECT_EXIST, data fails to be written to the row. One write CU and one read CU are consumed.
  • If the row that you want to update does not exist, the number of consumed CUs varies based on the value that you specified for the condition parameter.
    • If the value of the condition parameter is IGNORE, the number of consumed write CUs is rounded up from the value that is calculated by using the following formula: Number of consumed write CUs = (Size of data in all primary key columns of the row + Size of data in attribute columns that you want to update)/4 KB. If UpdateRow contains an attribute column that you want to delete, the length of the column name is calculated as the size of data in the column.
    • If the value of the condition parameter is EXPECT_EXIST, both write and read CUs are consumed. The number of consumed write CUs is calculated by using the formula that is used when the value of the condition parameter is IGNORE. The number of consumed read CUs is rounded up from the value that is calculated by using the following formula: Number of consumed read CUs = Size of data in primary key columns of the row/4 KB.

    For more information about how to calculate the data size, see Billing overview.

  • If the request times out and the results are undefined, CUs may or may not be consumed.
  • If an HTTP status code 5xx is returned, which indicates that an internal error occurred, the operation does not consume CUs. If other errors are returned, one write CU and one read CU are consumed.