pymsql excute_many 出现 not all arguments converted with on duplicate key update

来源:互联网 发布:美国 私人飞机 知乎 编辑:程序博客网 时间:2024/05/16 13:59
在使用pymysql的execute_many进行批量数据插入的时候,出现 not all arguments converted with on duplicate key update
sql = insert into test(a,b)values(%s,%s) on duplicate key update b=%s
params=[(1,2),(3,4),(5,6)]
db.executemany(sql,params)
一开始以为是%s跟参数没有对应上,然后去一个一个对,发现还是报这个错误。然后我尝试插入一条的时候,没有报错。证明不是%s跟参数对应不上的问题。
然后上网查资料。sql改成:
sql = insert into test(a,b)values(%s,%s) on duplicate key update b=values(b)就行了。
第一次知道mysql还有这种写法。

参考:
https://stackoverflow.com/questions/26337065/mysqldb-returns-not-all-arguments-converted-with-on-duplicate-key-update
https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
原创粉丝点击