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

在使用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还有这种写法。

参考:
发布了63 篇原创文章 · 获赞 28 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/kelindame/article/details/75171916