Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation on multi-statement queries #1137

Open
mattalbr opened this issue Nov 13, 2024 · 0 comments
Open

Add documentation on multi-statement queries #1137

mattalbr opened this issue Nov 13, 2024 · 0 comments
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API.

Comments

@mattalbr
Copy link

Is your feature request related to a problem? Please describe.
I'm unsure how to make the best use of the library. Say I have a query like:

CREATE TEMP TABLE matching_foos AS (
  SELECT foo_table.name, foo_table.id FROM foo_table
  WHERE foo_table.name LIKE  "%123%"
);
SELECT matching_foos.name, matching_foos.id
FROM matching_foos;

It's my understanding that as of #74 it's possible to execute this multi-statement query. But, I can't figure out how to build such a query using sqlalchemy statements. e.g. if I have

def get_matching_foos_query() -> sqlalchemy.selectable:
  return sqlalchemy.select(models.foo_table.c.name, models.foo_table.c.id).where(models.foo_table.c.name.like("%123%"))

How would I then turn that into a temp table and then reference that table? Do I have to do a literal compile and then throw it into a sqlalchemy.text? Is there any sqlalchemy-style invocation to support this use case using similar .c.column_a syntax?

Describe the solution you'd like
Documentation (in the main README perhaps? or a link to a test file?) demonstrating how to create pythonic multi-statement queries that leverage some amount of modularity (vs straight text). Ideally would love to see: CREATE TEMP TABLE and SET/DECLARE
Describe alternatives you've considered
I really want to avoid just sending text. Doing so loses all of sqlalchemy's power to create modular statements by reusing filters, selectables, etc.

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. label Nov 13, 2024
@shollyman shollyman assigned chalmerlowe and Linchin and unassigned PhongChuong Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API.
Projects
None yet
Development

No branches or pull requests

4 participants