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 support for MERGE DDL #428

Open
munro opened this issue Mar 16, 2022 · 4 comments
Open

Add support for MERGE DDL #428

munro opened this issue Mar 16, 2022 · 4 comments
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@munro
Copy link

munro commented Mar 16, 2022

Is your feature request related to a problem? Please describe.
Yes, programmatically generating MERGE statements.

Describe the solution you'd like
Adding support MERGE DDL operation in BigQuery.

https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement

Describe alternatives you've considered
Directly writing SQL code

Additional context
None

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. label Mar 16, 2022
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 17, 2022
@meredithslota meredithslota added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Mar 17, 2022
munro added a commit to munro/python-bigquery-sqlalchemy that referenced this issue Mar 17, 2022
munro added a commit to munro/python-bigquery-sqlalchemy that referenced this issue Mar 17, 2022
munro added a commit to munro/python-bigquery-sqlalchemy that referenced this issue Mar 17, 2022
munro added a commit to munro/python-bigquery-sqlalchemy that referenced this issue Mar 17, 2022
A MERGE statement is a DML statement that can combine INSERT, UPDATE, and DELETE
operations into a single statement and perform the operations atomically.

This commit introduces support for generating MERGE statements programmatically
with SQLAlchemy.

Refs: googleapis#428
@jlynchMicron
Copy link

Since the BiqQuery SQLalchemy dialect is based on the PostgreSQL dialect, would this implementation most likely follow the UPSERT syntax? https://docs.sqlalchemy.org/en/20/dialects/postgresql.html#insert-on-conflict-upsert

@jlynchMicron
Copy link

NVM, I now see the failed merge request that would just use more native BQ MERGE syntax.

@jlynchMicron
Copy link

jlynchMicron commented Dec 28, 2023

For anyone else waiting on this support that does not mind using the failed merge code above, I just copied that code to a folder and added it to my sqlalchemy_bigquery module by importing the folder (module) with the following init.py code:

import sqlalchemy_bigquery as sa_bq
from .merge import Merge

sa_bq.merge = Merge #Adding merge to sq_bq namespace.
sa_bq.__all__.append('MERGE')

@munro
Copy link
Author

munro commented Dec 30, 2023

yea it's just for BQ— don't quote me but if BQ & PG's MERGE syntax are that similar, it would probably work for 90% of the use cases if ya wanna fork it. I spent a bit of time making the SQL it spits out actually look nice 🪞

I am using the code in production, but ya I hadn't signed the CLA so it got dropped (my bad)

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. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants