How to construct GQL to not contain a value from a set?

老子叫甜甜 提交于 2019-12-31 01:45:32

问题


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()

回答1:


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).



来源:https://stackoverflow.com/questions/3807591/how-to-construct-gql-to-not-contain-a-value-from-a-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!