GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: support INSERT from SELECT clause with args by IlyaFaer · Pull Request #306 · googleapis/python-spanner

This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Conversation

@IlyaFaer

@IlyaFaer IlyaFaer commented Apr 12, 2021

Copy link
Copy Markdown

Spanner supports doing INSERT with values takes from a SELECT clause. However, DB API is processing such a cases incorrectly, so such a query, for example:

INSERT INTO manual_pk (id, data)
SELECT manual_pk.id + %s AS anon_1, manual_pk.data
FROM manual_pk
WHERE manual_pk.data IN (%s, %s)

Will fail with a syntax error:

400 Syntax error: Illegal input character \"%\" [at 3:23]\nSELECT manual_pk.id + %s AS anon_1, manual_pk.data\n

Fixing this bug.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
IlyaFaer
fix: support INSERT from SELECT clause with args
c84c1a0
@IlyaFaer IlyaFaer added api: spanner Issues related to the googleapis/python-spanner API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Apr 12, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Apr 12, 2021
IlyaFaer
the fix itself
f1dd612
IlyaFaer
IlyaFaer commented Apr 12, 2021
View reviewed changes
Comment thread google/cloud/spanner_dbapi/parse_utils.py
# Case b)
insert_sql = sanitize_literals_for_upload(insert_sql)
return {"sql_params_list": [(insert_sql, None)]}
return {"sql_params_list": [(insert_sql, params)]}

@IlyaFaer IlyaFaer Apr 12, 2021

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the previous author of the DB API didn't notice that INSERT from SELECT will be a case b), and it can include some args. Thus, passing None instead of args is not correct.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@IlyaFaer
IlyaFaer marked this pull request as ready for review April 12, 2021 08:42
@IlyaFaer
IlyaFaer requested review from a team and larkee April 12, 2021 08:42
larkee
larkee approved these changes Apr 14, 2021
View reviewed changes

@larkee larkee left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Does the docstring need updating to reflect this change?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
IlyaFaer
update docstrings
8ac6f06
AVaksman
AVaksman approved these changes Apr 14, 2021
View reviewed changes
@larkee
larkee merged commit 0dcda5e into googleapis:master Apr 15, 2021
@IlyaFaer
IlyaFaer deleted the insert_from_select branch April 15, 2021 07:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@AVaksman AVaksman AVaksman approved these changes
@larkee larkee larkee approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: spanner Issues related to the googleapis/python-spanner API. cla: yes This human has signed the Contributor License Agreement. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@IlyaFaer @AVaksman @larkee
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.