Home:ALL Converter>Adding multiple conditions in where clause in bulk update in sqlalchemy

Adding multiple conditions in where clause in bulk update in sqlalchemy

Ask Time:2018-11-16T20:15:15         Author:user1896796

Json Formatter

Below code for bulk update is working where benefits_dict is my list of dictionaries.

conn.execute(MedicalPlanBenefit.__table__.update()
                             .where(MedicalPlanBenefit.__table__.c.user_id == bindparam('user_id')),
                             benefits_dict)

Now when I go and add multiple conditions to my where clause like below, it doesn't work.

conn.execute(MedicalPlanBenefit.__table__.update()
                             .where(MedicalPlanBenefit.__table__.c.user_id == bindparam('user_id') & MedicalPlanBenefit.__table__.c.test_id == bindparam('test_id')),
                             benefits_dict)

How do you add multiple conditions in this case?

My benefits_dict:

{'user_id': 1, 'email_address' : '[email protected]', 'id':12, 'test_id': 31},
   {'user_id': 1, 'email_address' : '[email protected]', 'id':13, 'test_id': 31},
   {'user_id': 2, 'email_address' : '[email protected]', 'id':14, 'test_id': 31},
   {'user_id': 2, 'email_address' : '[email protected]', 'id':15, 'test_id': 31} 

Author:user1896796,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53337722/adding-multiple-conditions-in-where-clause-in-bulk-update-in-sqlalchemy
yy