gpt4 book ai didi

Python TypeError - MySQL executemany

转载 作者:可可西里 更新时间:2023-11-01 07:44:48 24 4
gpt4 key购买 nike

我正在使用 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 给 Nacho,TypeError 有点让人误会,在 VALUES 子句中使用 WHERE 是非法的。

关于Python TypeError - MySQL executemany,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22998621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com