我正在使用MySQLdb模块插入我的数据库。我有以下代码
sqlString = """INSERT INTO PERFORMER (PERFORMER)
VALUES (%s)
WHERE NOT EXISTS (SELECT * FROM PERFORMER P
WHERE P.PERFORMER = %s)"""
data = [(c, c) for c in self._performers]
self._cursor.executemany(sqlString, data)基本上,我想要插入self._performers中尚未在PERFORMERS表中的条目(这只是一个名称列表)。但是我得到了下面的TypeError
TypeError: not all arguments converted during string formatting全迹
Traceback (most recent call last):
File "tvGuide.py", line 437, in <module>
processing.UpdatePerformers()
File "tvGuide.py", line 307, in UpdatePerformers
self._cursor.executemany(sqlString, data)
File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 246, in executemany
self.errorhandler(self, TypeError, msg)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue TypeError: not all arguments converted during string formattingself._performers列表很长,但是下面是前几个条目的示例
['Lucy Alexander', 'Martin Roberts', 'Alistair Appleton', 'Zak Bagans', 'Aaron Goodwin', 'Nick Groff', 'John Zaffis', 'Ellen Pompeo', 'Patrick Dempsey',发布于 2014-04-11 07:34:55
+1对于Nacho来说,TypeError有点像红鲱鱼,在VALUES子句中使用WHERE是非法的。
https://stackoverflow.com/questions/22998621
复制相似问题