Bulk update in SQLAlchemy Core using WHERE

后端 未结 3 817
北恋
北恋 2020-11-30 07:17

I have managed to work with the bulk insert in SQLAlchemy like:

conn.execute(addresses.insert(), [ 
   {\'user_id\': 1, \'email_address\' : \'jack@yahoo.com\         


        
3条回答
  •  渐次进展
    2020-11-30 08:09

    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()
    

提交回复
热议问题