I have managed to work with the bulk insert in SQLAlchemy like:
conn.execute(addresses.insert(), [
{\'user_id\': 1, \'email_address\' : \'jack@yahoo.com\
The session has function called bulk_insert_mappings
and bulk_update_mappings
: documentation.
Be aware that you have to provide primary key in mappings
# List of dictionary including primary key
user_mappings = [{
'user_id': 1, # This is pk?
'email_address': 'jack@yahoo.com',
'_id': 1
}, ...]
session.bulk_update_mappings(User, user_mappings)
session.commit()