On Sat, Jan 26, 2019 at 5:51 PM mark.keller via sqlalchemy <[email protected]> wrote: > > Hi, > > I was working on adding support for our MERGE (upsert) command > (https://docs.snowflake.net/manuals/sql-reference/sql/merge.html) to > snowflake-sqlalchemy. > > First I tried to patch/replace the Table object to achieve an interface like > ... > meta = MetaData() > meta.reflect(bind=session.bind, only=['source_table', 'target_table']) > source_table = meta.tables['source_table'] > target_table = meta.tables['target_table'] > > merge = > source_table.merge_into(target_table).when_matched_update(...).when_not_matched_insert(...) > conn.execute(merge) > > I tried using the compiles decorator to register my own Table object, but > reflect seems to be creating the default Table object directly. > Is there a way to do this, or should I be adding MERGE in another way? > > The other way I was thinking about doing this is similar to: > https://docs.sqlalchemy.org/en/latest/core/compiler.html#compiling-sub-elements-of-a-custom-expression-construct
do it the second way. even though table has table.insert(), table.update(), it probably would be better that they didn't (there is insert(table), update(table) also). > This would yield in an interface like so: > from snowflake.sqlalchemy.base import MergeInto > ... > merge = MergeInto(target_table, source_table, source_table.c.column == > target_table.c.column) > merge.when_matched_update(...) > merge.when_not_matched_insert(...) > conn.execute(merge) > > I would like stay consistent with the rest of the library. > > Thank you for your hard on SQLAlchemy and your comments, > Mark > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
