Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 0f0d42f

Browse files
committed
Update sample
1 parent a32dd63 commit 0f0d42f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

samples/samples/snippets.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,15 @@ def insert_data(instance_id, database_id):
403403
# [END spanner_insert_data]
404404

405405

406-
# [START spanner_batch_write]
406+
# [START spanner_batch_write_at_least_once]
407407
def batch_write(instance_id, database_id):
408408
"""Inserts sample data into the given database via BatchWrite API.
409409
410410
The database and table must already exist and can be created using
411411
`create_database`.
412412
"""
413+
from google.rpc.code_pb2 import OK
414+
413415
spanner_client = spanner.Client()
414416
instance = spanner_client.instance(instance_id)
415417
database = instance.database(database_id)
@@ -429,7 +431,7 @@ def batch_write(instance_id, database_id):
429431
table="Singers",
430432
columns=("SingerId", "FirstName", "LastName"),
431433
values=[
432-
(17, "Marc", "Richards"),
434+
(17, "Marc", ""),
433435
(18, "Catalina", "Smith"),
434436
],
435437
)
@@ -443,12 +445,23 @@ def batch_write(instance_id, database_id):
443445
)
444446

445447
for response in groups.batch_write():
446-
print(response)
448+
if response.status.code == OK:
449+
print(
450+
"Mutation group indexes {} have been applied with commit timestamp {}".format(
451+
response.indexes, response.commit_timestamp
452+
)
453+
)
454+
else:
455+
print(
456+
"Mutation group indexes {} could not be applied with error {}".format(
457+
response.indexes, response.status
458+
)
459+
)
447460

448461
print("Inserted data.")
449462

450463

451-
# [END spanner_batch_write]
464+
# [END spanner_batch_write_at_least_once]
452465

453466

454467
# [START spanner_delete_data]

0 commit comments

Comments
 (0)