简体   繁体   中英

peewee raw query does not work with WITH statement

I have query which works in SQLite Spy (a tool for viewing SQLite Databases) but I can't get the query to work in python with peewee as a raw query.

The (simplified) query is

WITH tags(name) AS ( VALUES('foo'),('bar') ) SELECT * FROM tags

The (simplified) python code is:

from peewee import *

db = SqliteDatabase(":memory:")
db.execute_sql("WITH tags(name) AS ( VALUES('foo'),('bar') ) SELECT * FROM tags")

I get an error

peewee.OperationalError: near "WITH": syntax error

I also tried the RawQuery function or using SqliteExtDatabase from the PlayHouse extension.

Is this error caused by me or is it a problem of peewee?

CTE was introduced in SQLite as of version 3.8.3

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

it is very likely that your Python is using a previous version that does not support WITH Check sqlite3.sqlite_version_info

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM