python - SQLAlchemy:如何在更新语句中使用变量
问题描述
我试图在更新语句中使用变量作为键,但似乎不允许使用变量。
有表“disamb”:
+----+-----------+--------------------+-----------+--------------------+
| id | entity_a | id_of_entity_a | entity_b | id_of_entity |
+----+-----------+--------------------+-----------+--------------------+
| 0 | table | | bar | - |
+----+-----------+--------------------+-----------+--------------------+
和一个表“实体”:
+--------+----+-----------------------------------------------------------------+
| entity | id | paraphrase |
+--------+----+-----------------------------------------------------------------+
| table | 1 | An item of furniture with a flat top and one or more legs |
| table | 2 | A data arrangement with rows and columns |
| bar | 3 | A retail business establishment that serves alcoholic beverages |
| bar | 4 | a long item |
+--------+----+-----------------------------------------------------------------+
我的程序循环遍历表“disamb”中的列“entity_a”和“entity_b”,并在表“entities”中搜索相应的单词,问我选择哪个,然后(应该)将其写入相应的列“id_of_entity_a”resp . “id_of_entity_b”。
因此,在循环的某一点,变量具有例如以下值:
column_name = "id_of_entity_a"
id_of_entity = "1"
row = "0"
我尝试执行这段代码:
update_stmt = tbl.update().\
values(column_name=id_of_entity).\
where(tbl.columns.id == (row))
conn_mysql.execute(update_stmt)
它抛出错误:“sqlalchemy.exc.CompileError:未使用的列名:column_name”
我该如何解决这个问题?谢谢!
解决方案
推荐阅读
- swift - 使用自动布局以编程方式将自定义 UIView 与视图对齐
- android - 应用程序语言没有完全改变
- jax-rs - 如何从 JSON 对象序列化中排除 Weld 元数据
- opencv - 在运行交叉编译的 cpp 二进制文件时运行 poky 2.1.3 的 h3ulcb 中未处理的 2 级转换错误
- r - 多个 R Shiny 进程
- javascript - Google-Sheets - 根据单元格值打破循环
- bash - docker-compose 动态查看容器是否已启动(或:docker-compose 计划?)
- c# - 为什么这个方法调用不明确?
- qt - 边距和锚点在 Qt、QML 中效果不佳
- android - 如何保护类不被 MINIFY_ENABLED 删除?