我正在尝试使用 PYTHON 中的 MYSQL 在特定行中插入数据。
我尝试了以下代码:
sql = "INSERT INTO board (pages) VALUES (%s) WHERE (ASIN) = '" + asinList[x] + "'"
val = (a)
myCurser.execute(sql, val)
但是,我收到了这个错误:
"
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%s) WHERE (ASIN) = 'B07KWSRMK1'' "
如何解决?
最佳答案
INSERT
不支持带有 VALUES
的 WHERE
子句。
如果您确实想添加新行,那么您应该使用INSERT
。
sql = "INSERT INTO board (pages) VALUES (%s) '"
您可能希望更新现有行。在此您应该使用 UPDATE
:
sql = "UPDATE board
SET pages = %s
WHERE ASIN = %s"
关于python - 在 Python 中使用 MySQL 将数据插入特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56197704/