Updates the data of a row.
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:
|
condition | Yes | Specifies whether to perform row existence check before data is updated. Valid values:
| |
return_content | 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 | 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:
Tablestore SDK for Java: Update a single row of data
Tablestore SDK for Go: Update a single row of data
Tablestore SDK for Python: Update a single row of data
Tablestore SDK for Node.js: Update a single row of data
Tablestore SDK for .NET: Update a single row of data
Tablestore SDK for PHP: 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.