如何构造 GQL 以不包含集合中的值?

发布于 2024-09-25 03:20:36 字数 507 浏览 7 评论 0原文

是否可以从 db.Model 对象的键不在给定列表中的谷歌应用程序引擎数据库中进行选择?如果是这样,语法是什么?

模型类的示例:

class Spam(db.Model):
    field1 = db.BooleanProperty(default=false)
    field2 = db.IntegerProperty()

我想要执行但无法弄清楚的查询示例:

spam_results = db.GqlQuery(
"SELECT * FROM Spam WHERE key NOT IN :1 LIMIT 10", 
['ag1waWNreXByZXNlbnRzchMLEgxBbm5vdW5jZW1lbnQYjAEM', 
 'ag1waWNreXByZXNlbnRzchMLEgxBbm5vdW5jZW1lbnQYjgEM'])

for eggs in spam_results:
  print "id: %s" % a.key().id()

Is it possible to select from a google app engine db where the key of a db.Model object is not in a given list? If so, what would be the syntax?

Ex of a model class:

class Spam(db.Model):
    field1 = db.BooleanProperty(default=false)
    field2 = db.IntegerProperty()

Example of a query which I'd like to work but can't figure out:

spam_results = db.GqlQuery(
"SELECT * FROM Spam WHERE key NOT IN :1 LIMIT 10", 
['ag1waWNreXByZXNlbnRzchMLEgxBbm5vdW5jZW1lbnQYjAEM', 
 'ag1waWNreXByZXNlbnRzchMLEgxBbm5vdW5jZW1lbnQYjgEM'])

for eggs in spam_results:
  print "id: %s" % a.key().id()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧桑㈠ 2024-10-02 03:20:36

否 虽然应用程序引擎支持“IN”查询,但不支持“NOT IN”查询。

但是,如果您不想要的实体列表很小,那么您不妨检索每个实体并过滤掉您自己不需要的实体。

或者,如果要排除的实体列表占所有实体的很大一部分,则上述解决方案将相当低效。相反,也许您可​​以向模型添加一个附加属性,您可以使用它来过滤掉您不需要的实体(这是否可行将取决于您的特定需求和数据)。

No Though app engine supports an "IN" query, it does not support a "NOT IN" query.

However, if your list of entities you don't want is small, then you might as well just retrieve every entity and filter out the ones you don't need yourself.

Alternatively, if the list of entities you want to exclude is a large fraction of all entities, then the above solution would be rather inefficient. Instead, perhaps you could add an additional property to your model which you could use to filter out entities you don't want (whether or not this is possible will depend on your specific needs and data).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文