需要Python请求帮助吗

2024-05-23 17:05:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试执行以下操作:

cursor.execute("UPDATE 'produit' SET 'Top 1'=%s, 'Top 2'=%s, 'Top 3'=%s WHERE 'Id'=%s " % (n[2],n[1],n[0],i+1))
conn.commit()

但我得到以下错误:

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 ''produit' SET 'Top 1'=1, 'Top 2'=3, 'Top 3'=5 WHERE 'Id'=1' at line 1


Tags: thetoidexecuteyourtop错误update
2条回答

对愚蠢地包含空格或其他标点符号的表和列名使用backtics。你知道吗

不是

"UPDATE 'produit' SET 'Top 1'=%s, ...

而是:

"UPDATE `produit` SET `Top 1`=%s, ...
SET 'Top 1'=%s, 'Top 2'=%s, 'Top 3'=%s

我相信SQL是在寻找字段名来代替'Top 1', 'Top 2', 'Top 3'。如果要更新第1、第2和第3列,则不能以这种方式进行更新。你知道吗

https://mariadb.com/kb/en/sql-99/update-examples/

相关问题 更多 >