You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New executemany() implementation supporting UPDATE query #506
The problem is with the regular expression RE_INSERT_VALUES in cursors.py
You can see in this screenshot that not all the %s are captured by the regular expression and you get this error "TypeError: not all arguments converted during string formatting" on line 213 " v = values % escape(next(args), conn)
I never want add real SQL parser. So I never support such query by regular expression.
executemany() by multi query will solve it.
But I don't have motivation for improving this project now.
It seems that execute() works well for code like cursor.execute("insert into t(c1, c2) values(%s, %s) on duplicate key update c1=%s, c2=%s", (1, 2)*2), all the 4 args will be assigned.
But executemany() for insert into ... on duplicate key update failed because RE_INSERT_VALUES can not match placeholders after ON DUPLICATE, there're 2 solutions:
use execute instead of executemany for insert into ... on duplicate key update
use mysql VALUES() functions after update to refer values for insertion, like cursor.executemany("insert into t(c1, c2) values(%s, %s) on duplicate key update c1=Values(c1), c2=Values(c2)", [(1, 2), (3, 4)])
Activity
paytmMatt commentedon Jun 14, 2018
The problem is with the regular expression RE_INSERT_VALUES in cursors.py
You can see in this screenshot that not all the %s are captured by the regular expression and you get this error "TypeError: not all arguments converted during string formatting" on line 213 "
v = values % escape(next(args), conn)methane commentedon Jun 14, 2018
I never want add real SQL parser. So I never support such query by regular expression.
executemany() by multi query will solve it.
But I don't have motivation for improving this project now.
methane commentedon Jun 14, 2018
MariaDB supports original bulk insert.
https://mariadb.com/kb/en/library/bulk-insert-row-wise-binding/
If MySQL follow MariaDB, I want to implement it, instead of multi statement hack.
OmniTroid commentedon Mar 10, 2020
+1 would like to see this implemented as well.
Caozhitong commentedon Jul 18, 2020
+1
langshi2555 commentedon Jul 23, 2020
+1
piweidong commentedon Sep 11, 2021
+1 would like to see this implemented as soon as possible.
realcp1018 commentedon Sep 11, 2024
It seems that execute() works well for code like
cursor.execute("insert into t(c1, c2) values(%s, %s) on duplicate key update c1=%s, c2=%s", (1, 2)*2), all the 4 args will be assigned.But executemany() for
insert into ... on duplicate key updatefailed because RE_INSERT_VALUES can not match placeholders afterON DUPLICATE, there're 2 solutions:insert into ... on duplicate key updatecursor.executemany("insert into t(c1, c2) values(%s, %s) on duplicate key update c1=Values(c1), c2=Values(c2)", [(1, 2), (3, 4)])