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

时间:2015-12-09 14:35:42

标签: python sql sqlite peewee

我的查询在SQLite Spy(查看SQLite数据库的工具)中有效,但我无法使用peewee作为原始查询在python中使用查询。

(简化)查询

CREATE OR REPLACE PROCEDURE "MY_SCHEMA"."TEST" AS

CURSOR mySelectCursor IS
    SELECT 
        VALUE(table_temp) AS "XMLTYPE"
    FROM 
        XMLTABLE('/ROWSET/ROW' PASSING 
            DBMS_XMLGEN.GETXMLTYPE('
                SELECT ''1a'' as "column1", ''1b'' as "column2" FROM DUAL
                UNION ALL
                SELECT ''2a'' as "column1", ''2b'' as "column2" FROM DUAL
            ')
        ) table_temp;
BEGIN

FOR mySelect IN mySelectCursor
    LOOP
        dbms_output.put_line(mySelect."XMLTYPE".getClobVal());
    END LOOP;
END;

-- Output is :

--<ROW><column1>1a</column1><column2>1b</column2></ROW>
--<ROW><column1>2a</column1><column2>2b</column2></ROW>

(简化)python代码是:

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

我收到错误

from peewee import *

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

我也尝试过RawQuery函数或使用PlayHouse扩展程序中的SqliteExtDatabase。

这是由我造成的错误还是小便的问题?

1 个答案:

答案 0 :(得分:2)

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