'Get Row Count in SQLAlchemy Bulk Operations
Is there a way to get the number of rows affected as a result of executing session.bulk_insert_mappings() and session.bulk_update_mappings()?
I have seen that you can use ResultProxy.rowcount to get this number with connection.execute(), but how does it work with these bulk operations?
Solution 1:[1]
Unfortunately bulk_insert_mappings and bulk_update_mappings do not return the number of rows created/updated.
If your update is the same for all the objects (for example increasing some int field by 1) you could use this:
updatedCount = session.query(People).filter(People.name == "Nadav").upadte({People.age: People.age + 1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kremzon |
