you can use a mapped class directly with pg's insert() construct: insert(MyClass).values(...).on_conflict(...)
are you referring to being able to pass instances of mapped objects to the values? Just pull these out of each object's `__dict__`, it's much more efficient than bulk_insert_mappings. You can get object instances back too using the technique shown at https://docs.sqlalchemy.org/en/14/orm/session_basics.html#selecting-orm-objects-inline-with-update-returning-or-insert-returning , basically create the SQL insert() statement you want, make sure it uses returning(), then use select(MyModel).from_statement(my_insert) to get object instances back. On Tue, Aug 24, 2021, at 12:17 PM, Anthony Catel wrote: > Hey, > > I'm looking for a way to builk upsert using pg's "on_conflict_do_update" in > a way that would allow me to use a mapper classe (because the objects I want > to insert/update are joined-inheritance). > > bulk_insert_mappings() would allow me to use its "return_defaults" and to > provide a Mapper classe. But I couldn't figure out a way to combine it with > "on_conflict_do_update". > > Any hack I could use to glue these two? > > Thanks! > > > -- > 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 sqlalchemy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/48c6462a-c4fd-46c7-aead-464b29a03e27n%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/48c6462a-c4fd-46c7-aead-464b29a03e27n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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 sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/1dda86f7-1a70-4ba8-8b0d-fb45c3d62bc5%40www.fastmail.com.