python - SQLAlchemy 文本参数绑定给出“?”
问题描述
我正在为 SQL Server 使用 ODBC 驱动程序 17
我有这个:
q = text('select top 10 * from :x')
conn.execute(q, x="mytable")
返回失败:
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Must declare the table variable "@P1". (1087) (SQLExecDirectW)') [SQL: select top 10 * from ?] [parameters: ('mytable',)]
然而,跑步q = test('select top 10 * from mytable')
有效。
正如我所尝试的那样,我迷失了方向bindparams
。
解决方案
马蒂金的评论是正确的。绑定参数仅适用于数据。
q = text('select top 10 * from :x')
conn.execute(q, x="mytable")
是无效的。
但是这个,
q = text('select :x from mytable')
conn.execute(q, x="thing1")
作品。
推荐阅读
- oracle - 如何在两个日期之间的表上获取日期范围分区名称(给定日期范围)
- javascript - 如何在java中的mapReduce中调用mongodb服务器端函数
- docker - Linkerd 边车注入
- php - 更好的性能,JOIN 还是多个查询?
- git - Git:提交日期的批量更改
- javascript - 使用 Numeral JS 将任何数字转换为相同的比例
- git - 作为 git 中 master 合并的一部分提交的文件列表
- django - 在 django 的特定日期范围内查询 GET x
- java - Select only a subset of an Entities Collection
- javascript - 如何在 d3.transition 期间正确访问 SVG 元素的转换