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

标签 python sql sqlite peewee

我有一个可在 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

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

关于python - peewee 原始查询不适用于WITH 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34181458/

相关文章:

python - 如何在 pandas 中保存字典的字典(或具有类似功能的东西)?

sql - xml 到 sql 表

python - 从 sqlite3 触发器启动 Python 脚本

sql - 两个 SUM 查询在一起

php - 当MySQL中有多个条件时,如何计算排名

sqlite 通过网络共享进行故障转移

android - 在android中使用内容提供者获取联系电话

python - C 和 Python 集成 : name of callback function

javascript - JSON 从 python json.dumps 到 javascript JSON.parse() 并转义\"

python - 迭代器对象、PyCapsules 和内存性能