sun*_*day -4 python sqlalchemy flask-sqlalchemy
我有一个 SQLAlchemy 查询,如下所示:
query = db.session.query(
Place.name,
Place.population,
).filter(Place.population==8000)
Run Code Online (Sandbox Code Playgroud)
但是当我打印查询时,结果如下:
SELECT place.name AS place_name, place.population AS place_population
FROM place
WHERE place.population = %(population_1)s
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它不断用 替换我的过滤条件%(population_1)s。这个查询是 Flask 应用程序的一部分,也许有什么我不明白的地方?
编辑:更改标题以更描述实际问题。
它的行为正是应有的。这就是打印查询的方式。
from sqlalchemy.dialects import postgresql
query = statement.compile(dialect=postgresql.dialect(),compile_kwargs={"literal_binds": True})
print(query) # will print the compiled query statement againt the dialect.
Run Code Online (Sandbox Code Playgroud)