Created
September 8, 2015 18:24
-
-
Save doobeh/b16e800cdd51d6413c09 to your computer and use it in GitHub Desktop.
SQLAlchemy bulk updates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Quick example showing how to do a bulk update into the database | |
using SQLAlchemy, without interacting heavily with the ORM. | |
""" | |
from sqlalchemy.sql.expression import bindparam | |
stmt = addresses.update().\ | |
where(addresses.c.id == bindparam('_id')).\ | |
values({ | |
'user_id': bindparam('user_id'), | |
'email_address': bindparam('email_address'), | |
}) | |
conn.execute(stmt, [ | |
{'user_id': 1, 'email_address' : '[email protected]', '_id':1}, | |
{'user_id': 1, 'email_address' : '[email protected]', '_id':2}, | |
{'user_id': 2, 'email_address' : '[email protected]', '_id':3}, | |
{'user_id': 2, 'email_address' : '[email protected]', '_id':4}, | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @doobeh are you familiar with bulk_update_mapping.
WDYT compare to this https://docs.sqlalchemy.org/en/14/_modules/examples/performance/bulk_updates.html