如何构造 GQL 以不包含集合中的值?
是否可以从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
否 虽然应用程序引擎支持“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).