pymysql中的 executemany 使用问题 |
您所在的位置:网站首页 › excutemany语法 › pymysql中的 executemany 使用问题 |
想使用 executemany 方法进行一次插入多条记录,同时实现存在就更新的要求。 在使用INSERT INTO ....... ON DUPLICATE KEY UPDATE 进行多条数据插入是总是达不到想要的效果。调查后成功的sql写法如下: sql = """ INSERT INTO face_user ( name, description, user_id, gender, age,group_name) VALUES (%s,%s,%s,%s,%s,%s) ON duplicate KEY UPDATE age=values(age),group_name=values(group_name) """可参见 https://stackoverflow.com/questions/12825232/python-execute-many-with-on-duplicate-key-update when you use "ON DUPLICATE KEY UPDATE" in python, you need to write sql like this: sql = 'insert into A (id, last_date, count) values(%s, %s, %s) on duplicate key update last_date=values(last_date),count=count+values(count)' |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |