运行 Cloud Spanner 中多个查询的事务
Running transaction for multiple queries in Cloud Spanner
我有一堆 DDL 和 DML 语句,我想 运行 在具有特定超时的事务中。我在客户端使用 python (google-cloud-spanner
)。
对如何构建交易有任何见解吗?
通过检查 Cloud Spanner Python docs,您将能够看到 run_in_transaction()
将自动处理提交和回滚,因此您不必手动触发它们。这是注释:
Rather than calling commit()
or rollback()
manually, you should use run_in_transaction()
to run the function that you need. The transaction’s commit()
method will be called automatically if the with block exits without raising an exception. The function will automatically be retried for Aborted errors, but will raise on GoogleAPICallError
and rollback()
will be called on all others.
我有一堆 DDL 和 DML 语句,我想 运行 在具有特定超时的事务中。我在客户端使用 python (google-cloud-spanner
)。
对如何构建交易有任何见解吗?
通过检查 Cloud Spanner Python docs,您将能够看到 run_in_transaction()
将自动处理提交和回滚,因此您不必手动触发它们。这是注释:
Rather than calling
commit()
orrollback()
manually, you should userun_in_transaction()
to run the function that you need. The transaction’scommit()
method will be called automatically if the with block exits without raising an exception. The function will automatically be retried for Aborted errors, but will raise onGoogleAPICallError
androllback()
will be called on all others.