python - 在 Python 中使用 MySQL 将数据插入特定行

标签 python mysql sql insert sql-insert

我正在尝试使用 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 不支持带有 VALUESWHERE 子句。

如果您确实想添加新行,那么您应该使用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/

相关文章:

python - 查找给定节点的最高权重边

python - python 3 中的 coerce() 等价物

Python 评估和评分学生的代码

php - 需要 PHP 和 MySQL 保存游戏进度的反馈

mysql - MySQL 中的情况与计数

WHILE 中的 PHP 数组

mysql - 如何隔离数据库中不存在的记录列表

python - 可调用前缀 : takes 0 positional arguments but 2 were given 中的 Discord.py 错误

php - 什么是参数化查询?

sql - T-SQL 选择没有事件的帐户