我有一个可在 SQLite Spy(用于查看 SQLite 数据库的工具)中运行的查询,但我无法使用 peewee 作为原始查询让该查询在 python 中运行。
(简化的)查询是
WITH tags(name) AS ( VALUES('foo'),('bar') ) SELECT * FROM tags
(简化的)Python 代码是:
from peewee import *
db = SqliteDatabase(":memory:")
db.execute_sql("WITH tags(name) AS ( VALUES('foo'),('bar') ) SELECT * FROM tags")
我收到错误
peewee.OperationalError: near "WITH": syntax error
我还尝试了 RawQuery 函数或使用 PlayHouse 扩展中的 SqliteExtDatabase。
这个错误是我造成的还是peewee的问题?
最佳答案
CTE 自 3.8.3 版本起在 SQLite 中引入
http://www.sqlite.org/releaselog/3_8_3.html
你的Python很可能使用的是不支持WITH的早期版本 检查 sqlite3.sqlite_version_info
关于python - peewee 原始查询不适用于WITH 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34181458/