All Products
Search
Document Center

Tablestore:UpdateRow

Last Updated:Aug 08, 2024

Updates the data of a row.

Note

If the specified row does not exist, a new row is inserted. 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;
    optional string transaction_id = 5;
}

Parameter

Type

Required

Description

table_name

string

Yes

The name of the table whose data you want to update.

row_change

bytes

Yes

The data that you want to update, including primary key columns and attribute columns. The data is encoded in the PlainBuffer format. For more information, see PlainBuffer.

Tablestore adds, modifies, or deletes the values in the specified attribute columns of the row based on the value of UpdateType in row_change. The columns that exist in the row but are not specified by row_change are not affected.

Valid values of UpdateType:

  • PUT: The value must be a valid value of an attribute column. 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

    The row exists even if all attribute columns of the row are deleted. To delete the row, call the DeleteRow operation.

condition

Condition

Yes

Specifies whether to perform row existence check before data is updated. Valid values:

  • IGNORE (default): Row existence check is not performed. 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 data type after the row is successfully written. Only the primary key can be returned. This parameter is mainly used by the auto-increment primary key column feature.

transaction_id

string

No

The ID of the local transaction. This parameter is required if you use the local transaction feature to read data.

Response syntax

message UpdateRowResponse {
    required ConsumedCapacity consumed = 1;
    optional bytes row = 2;
}

Parameter

Type

Description

consumed

ConsumedCapacity

The number of capacity units (CUs) that are consumed by the operation. For more information, see CU consumption.

row

bytes

The data that is returned if you specify a value for return_content. If you do not specify a value for return_content or no return value exists, 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 single row of data:

CU consumption

  • If the row that you want to update does not exist, the number of CUs that are consumed 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 calculation result of 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 exists, the number of CUs that are consumed 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 calculation result of 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, an internal error occurred. In this case, the operation does not consume CUs. If other errors are returned, one write CU and one read CU are consumed.