Python TypeError - MySQL executemany

时间:2014-04-10 20:44:13

标签: python mysql

我正在使用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 formatting

self._performers列表很长,但这里是前几个条目的样本

['Lucy Alexander', 'Martin Roberts', 'Alistair Appleton', 'Zak Bagans', 'Aaron Goodwin', 'Nick Groff', 'John Zaffis', 'Ellen Pompeo', 'Patrick Dempsey',

1 个答案:

答案 0 :(得分:0)

+1到Nacho,TypeError有点像redherring,使用带有VALUES子句的WHERE是违法的。