循环 sql 查询中变量的压缩列表

pyth0nBen

我有一个要更新的表,column1 是主键

| chute | five |
|-------|------|
| Fa01  | null |
|-------|------|
| Fa02  | null |
|-------|------|
| Fa03  | null |
|-------|------|

我想用基于第 1 列中的键的数据列表更新第 2 列。

sort_list = [('10.0','Fa01'),('23.0','Fa02'),('35.0','Fa03'),('9.0','Fa04')]

query = "UPDATE ship_divert SET five = %s, WHERE chute = %s"
cursor.executemany(query,sort_list)

但是,当我运行包含此查询的函数时出现以下错误

'...for the right syntax to use near 'WHERE chute = 'Fa01''

我已经在我的 mysql 控制台上测试了没有变量的查询并且它有效

UPDATE ship_divert   
SET five='28.0'  
WHERE chute = 'Fa02'

我的脚本中的语法在哪里不正确?

假真

您需要,在sql中删除

query = "UPDATE ship_divert SET five = %s, WHERE chute = %s"
                                         ^

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章