Bulk update in SQLAlchemy Core using WHERE

后端 未结 3 816
北恋
北恋 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 07:58

    @Jongbin Park's solution DID work for me with a composite primary key. (Azure SQL Server).

    update_vals = []
    update_vals.append(dict(Name='name_a', StartDate='2020-05-26 20:17:32', EndDate='2020-05-26 20:46:03', Comment='TEST COMMENT 1'))
    update_vals.append(dict(Name='name_b', StartDate='2020-05-26 21:31:16', EndDate='2020-05-26 21:38:37', Comment='TEST COMMENT 2'))
    s.bulk_update_mappings(MyTable, update_vals)
    s.commit()
    

    where Name, StartDate, and EndDate are all part of the composite pk. 'Comment' is the value to update in the db

提交回复
热议问题