Google App Engine: BadQueryError: Parse Error: Expected no additional symbols at symbol GROUP

Google App Engine: BadQueryError: Parse Error: Expected no additional symbols at symbol GROUP

我有一个 Google App Engine 数据存储 NDB 模型

class Track(ndb.Model):
    datetime = ndb.DateTimeProperty(indexed=True, required=True)
    title = ndb.StringProperty(indexed=True, required=True)
    artist = ndb.StringProperty(indexed=True, required=True)

并且我希望使用 GROUP BY GQL clause 将在不同日期时间播放的匹配曲目按标题和艺术家分组。我不确定为什么此 GQL 查询不起作用:

qry = ndb.gql("SELECT * FROM Track GROUP BY title, artist")

其中 returns 错误 BadQueryError: Parse Error: Expected no additional symbols at symbol GROUP 而以下工作正常

qry = ndb.gql("SELECT DISTINCT title, artist FROM Track")

当我在查询中放置一些任意子句 X 时,也会发生 BadQueryError: Parse Error: Expected no additional symbols at symbol X 错误,这表明 GQL 不支持 GROUP BY GQL 子句(如此处建议的旧答案) 即使它存在于 documentation.

GROUP BY 在 GQL 中不受 App Engine Datastore 支持,因此您必须先按顺序排序,然后再在您的应用程序中进行 post 筛选。

您 link 的文档适用于 Google Cloud Datastore(独立版本)的 v1beta2。对于 App Engine 数据存储,read here instead for GQL