Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Peewee 3-Python-Rank查询结果_Python 3.x_Peewee - Fatal编程技术网

Python 3.x Peewee 3-Python-Rank查询结果

Python 3.x Peewee 3-Python-Rank查询结果,python-3.x,peewee,Python 3.x,Peewee,我有一个带有注释(id、标题、父项)的自引用db表。 [注意:表的自引用属性与问题无关] 我想按标题的字母顺序排列,并根据其id查找特定注释的排名(=顺序)。我用Peewee3作为ORM DB型号: class Note(Model): title = CharField() parent = ForeignKeyField('self', backref='children', null = True) 代码: noteAlias = Note.alias() subquer

我有一个带有注释(id、标题、父项)的自引用db表。
[注意:表的自引用属性与问题无关]
我想按标题的字母顺序排列,并根据其
id
查找特定注释的排名(=顺序)。我用Peewee3作为ORM

DB型号:

class Note(Model):
    title = CharField()
    parent = ForeignKeyField('self', backref='children', null = True)
代码:

noteAlias = Note.alias()
subquery = (noteAlias.select(noteAlias.id, fn.RANK().over(partition_by=[noteAlias.title], order_by=[noteAlias.title]).alias('rank')).where(noteAlias.parent.is_null()).alias('subq'))
query = (Note.select(subquery.c.id, subquery.c.rank).from_(subquery).where(subquery.c.id == 5))
print("Rank of element is: " + str(query.rank))
此代码给出了以下错误:

cursor.execute(sql, params or ())
sqlite3.OperationalError: near "(": syntax error
SQLite测试
如果我只是直接针对我的db运行此sqlite代码:

SELECT (title, ROW_NUMBER() OVER (ORDER BY title) AS placement) FROM note

我得到错误:
near“,”:语法错误:

您的SQLite版本可能不支持窗口功能,因为我相信这是最近在3.25中添加的。

首先:非常感谢您的帮助,非常感谢。你是对的,我得出了同样的结论。我的SQLite版本是3.11,但仅从3.25开始支持窗口函数。我运行的是LinuxMint18.3(完全更新)和Mint19.3(最新版本),但在这两种情况下,SQLite版本都<3.25。我正在用Python GTK3开发一个开源软件。我想我可以在我的电脑上安装sqlite3软件包的非不稳定版本(不知道如何安装);但是在任何情况下,我的软件都不能在Mint软件管理器中使用,最终用户也必须这样做。等等。。。科利弗/皮维。。。你就是那个科利弗??!!??非常感谢你出色的工作。皮维真是太棒了!!您可以尝试将sqlite的自定义构建与python驱动程序静态链接:--peewee将使用pysqlite3(如果可用)。