peewee 原始查询不适用于 WITH 语句

peewee raw query does not work with WITH statement

我有一个在 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 在 SQLite 3.8.3 版本中引入

http://www.sqlite.org/releaselog/3_8_3.html

很可能您的Python使用的是不支持WITH的旧版本 检查 sqlite3.sqlite_version_info

https://docs.python.org/2/library/sqlite3.html