Repository navigation
Conversation
PostgreSQL-dialect Spanner uses UPDATE ... RETURNING to inspect modified columns without issuing a separate SELECT.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request adds a new sample script and tests demonstrating how to execute a PostgreSQL-dialect Spanner UPDATE DML statement with a RETURNING clause. The feedback recommends safely accessing results.stats to prevent a potential AttributeError if the server does not return query statistics.
| ) | ||
| for row in results: | ||
| budgets.append(int(row[0] or 0)) | ||
| row_counts.append(int(results.stats.row_count_exact)) |
There was a problem hiding this comment.
The results.stats property can be None if the server does not return query statistics. To prevent a potential AttributeError: 'NoneType' object has no attribute 'row_count_exact', you should safely access row_count_exact using a conditional check or helper.
| row_counts.append(int(results.stats.row_count_exact)) | |
| row_count = results.stats.row_count_exact if results.stats else 0 | |
| row_counts.append(int(row_count)) |
There was a problem hiding this comment.
Thanks! This comment refers to an earlier revision of this file; the code here has since been reworked in later commits, so this thread no longer applies to the current diff.
Uses a nonlocal row counter with a defensive results.stats check and omits project identifiers from stdout and stderr.
…l_returning Problem: multi-line SQL and DDL statements were written as adjacent string fragments. That style is easy to get wrong (a missing trailing space joins two SQL tokens) and is harder to read than the statement itself, and the samples in this set mixed it with triple-quoted SQL. Solution: write each multi-line statement as a single triple-quoted string, matching the layout already used by the other samples. Only whitespace between SQL tokens changes; the statements are otherwise identical. Files updated: - spanner/postgresql/src/spanner_postgresql/postgresql_update_dml_returning.py
Description
PostgreSQL-dialect Spanner databases use
UPDATE ... RETURNINGto return updated column values directly from a read-write transaction.Adds
spanner_postgresql_update_dml_returningusing the canonical cross-language region tag.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions