Inserts, modifies, or deletes multiple rows of data from one or more tables at the same time.
The BatchWriteRow operation is a set of PutRow, UpdateRow, or DeleteRow operations. If you call the BatchWriteRow operation, each PutRow, UpdateRow, or DeleteRow operation is separately performed, the response to each PutRow, UpdateRow, or DeleteRow operation is separately returned, and consumption units (CUs) are separately calculated for each PutRow, UpdateRow, or DeleteRow operation.
If you call the BacthWriteRow operation instead of calling the PutRow, UpdateRow, or DeleteRow operation multiple times, the response time is reduced, and the data write performance is improved.
Request syntax
message BatchWriteRowRequest {
repeated TableInBatchWriteRowRequest tables = 1;
optional string transaction_id = 2;
optional bool is_atomic = 3;
}
Parameter | Type | Required | Description |
tables | Yes | The rows on which you want to perform the batch write operation. An error is returned if any of the following situations exist:
| |
transaction_id | string | No | The ID of the local transaction. This parameter is required if you use the local transaction feature to write data in batches. |
is_atomic | bool | No | Specifies whether the batch write operation is performed as atomic operations. |
Response syntax
The BatchWriteRow operation may partially fail at the row level. However, the operation still returns the HTTP 200 status code. The application must check errors in RowInBatchWriteRowResponse to confirm the execution result for each row and then proceed accordingly.
message BatchWriteRowResponse {
repeated TableInBatchWriteRowResponse tables = 1;
}
Parameter | Type | Description |
tables | The response to each operation for each table. The response contains the execution results, error codes, and the number of consumed CUs. The order of the TableInBatchWriteRowResponse methods in the response is the same as the order of the TableInBatchWriteRowRequest methods in BatchWriteRowRequest. The order of the RowInBatchWriteRowResponse methods that are contained in put_rows, update_rows, or delete_rows in each TableInBatchWriteRowRequest method is the same as the order of the PutRowInBatchWriteRowRequest, UpdateRowInBatchWriteRowRequest, or DeleteRowInBatchWriteRowRequest methods that are contained in put_rows, update_rows, or delete_rows in TableInBatchWriteRowRequest. If a row fails to be read, the value of is_ok in RowInBatchWriteRowResponse is false for the row. |
Use Tablestore SDKs
You can use the following Tablestore SDKs to insert, modify, or delete multiple rows of data from one or more tables at the same time:
Tablestore SDK for Java: Write multiple rows of data in a batch
Tablestore SDK for Go: Write multiple rows of data in a batch
Tablestore SDK for Python: Write multiple rows of data in a batch
Tablestore SDK for Node.js: Write multiple rows of data in a batch
Tablestore SDK for .NET: Write multiple rows of data in a batch
Tablestore SDK for PHP: Write multiple rows of data in a batch
CU consumption
- If the operation fails, no CUs are consumed.
If the request times out and the results are undefined, CUs may or may not be consumed.
In other scenarios, each PutRowInBatchWriteRowRequest, UpdateRowInBatchWriteRowRequest, or DeleteRowInBatchWriteRowRequest method is considered a PutRow, UpdateRow, or DeleteRow operation for which CUs are separately calculated. For more information, see PutRow, UpdateRow, and DeleteRow.