Hi SQLAlchemy wizards.

I was interested in using the new bulk operations API 
(http://docs.sqlalchemy.org/en/latest/orm/persistence_techniques.html#bulk-operations)
 
but was looking for some advice based on my use case.

I have a class “FooDerived” which corresponds to a table that is linked to 
“FooBase” using joined table inheritance. I want to use the 
bulk_save_objects method to save, lets say 100,000 instances of 
“FooDerived”.

One option would be the following:

```
session.bulk_save_objects([FooBase() for i in range(100000)])
session.flush()
foo_base_models = FooBase.query.filter(/* Assume its possible to filter for 
the newly created objects*/).all()
session.bulk_save_objects([FooDerived(id=base.id) for base in 
foo_base_models])
```

Is there a better way?

Thank you!

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to