【发布时间】:2012-10-01 06:31:31
【问题描述】:
我正在尝试使用以下脚本在 python 中执行重复密钥更新:
# data from a previous query (returns 4 integers in each row)
rows = first_cursor.fetchall()
query="""
INSERT INTO data (a, b, c)
VALUES (%s,%s,%s) ON DUPLICATE KEY UPDATE a=%s
"""
second_cursor.executemany(query,rows)
我收到此错误:
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 212, in executemany
self.errorhandler(self, TypeError, msg)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
TypeError: not all arguments converted during string formatting
如果不创建我自己的循环,这是否可能?
【问题讨论】:
-
当项目的数量与您应该填写的内容和您实际传递的内容不匹配时,会发生此错误。 >>> a = 1 >>> b = 2 >>> print "%s" % (a,b) Traceback(最近一次调用最后):文件“
”,第 1 行,在 类型错误:在字符串格式化期间并非所有参数都转换 >>>
标签: python mysql-python