Stay organized with collections
Save and categorize content based on your preferences.
Batches the supplied mutation groups in a collection of efficient
transactions. All mutations in a group are committed atomically.
However, mutations across groups can be committed non-atomically in an
unspecified order and thus, they must be independent of each other.
Partial failure is possible, that is, some groups might have been
committed successfully, while some might have failed. The results of
individual batches are streamed into the response as the batches are
applied. BatchWrite requests are not replay protected, meaning that
each mutation group can be applied more than once. Replays of
non-idempotent mutations can have undesirable effects. For example,
replays of an insert mutation can produce an already exists error or if
you use generated or commit timestamp-based keys, it can result in
additional rows being added to the mutation's table. We recommend
structuring your mutation groups to be idempotent to avoid this issue.
For more information about retries and long-running operations, see
Understand connectors.
Arguments
Parameters
session
string
Required. The session in which the batch request is to be run.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Method: googleapis.spanner.v1.projects.instances.databases.sessions.batchWrite\n\nBatches the supplied mutation groups in a collection of efficient\ntransactions. All mutations in a group are committed atomically.\nHowever, mutations across groups can be committed non-atomically in an\nunspecified order and thus, they must be independent of each other.\nPartial failure is possible, that is, some groups might have been\ncommitted successfully, while some might have failed. The results of\nindividual batches are streamed into the response as the batches are\napplied. `BatchWrite` requests are not replay protected, meaning that\neach mutation group can be applied more than once. Replays of\nnon-idempotent mutations can have undesirable effects. For example,\nreplays of an insert mutation can produce an already exists error or if\nyou use generated or commit timestamp-based keys, it can result in\nadditional rows being added to the mutation's table. We recommend\nstructuring your mutation groups to be idempotent to avoid this issue.\n\nFor more information about retries and long-running operations, see\n[Understand connectors]().\n\nArguments\n---------\n\nRaised exceptions\n-----------------\n\nResponse\n--------\n\nIf successful, the response contains an instance of [`BatchWriteResponse`](https://cloud.google.com/workflows/docs/reference/googleapis/spanner/v1/Overview#BatchWriteResponse).\n\nSubworkflow snippet\n-------------------\n\nSome fields might be optional or required.\nTo identify required fields, refer to the [API documentation](https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.databases.sessions/batchWrite). \n\n### YAML\n\n```yaml\n- batchWrite:\n call: googleapis.spanner.v1.projects.instances.databases.sessions.batchWrite\n args:\n session: ...\n body:\n excludeTxnFromChangeStreams: ...\n mutationGroups: ...\n requestOptions:\n priority: ...\n requestTag: ...\n transactionTag: ...\n result: batchWriteResult\n```\n\n### JSON\n\n```json\n[\n {\n \"batchWrite\": {\n \"call\": \"googleapis.spanner.v1.projects.instances.databases.sessions.batchWrite\",\n \"args\": {\n \"session\": \"...\",\n \"body\": {\n \"excludeTxnFromChangeStreams\": \"...\",\n \"mutationGroups\": \"...\",\n \"requestOptions\": {\n \"priority\": \"...\",\n \"requestTag\": \"...\",\n \"transactionTag\": \"...\"\n }\n }\n },\n \"result\": \"batchWriteResult\"\n }\n }\n]\n```"]]