Search code examples
javagoogle-app-enginegqlgqlquery

Using List in GQL Filter


How can I make a selection in GQL using a List as filter.

If I have the class

public class Obj{

    @Persistent
    private Long name;

}

How can I get all Obj's that the name are not in a list?


Solution

  • You can get the results by chain all filters together.

    SELECT * FROM User where email != '[email protected]' and email != '[email protected]' and email != '[email protected]'
    

    Python Code

    q = User.all()
    for i in ilist:
        q = q.filter("email = ", i)
    

    But you may need to know there are some limitations for this kind of query.

    Note: The IN and != operators use multiple queries behind the scenes. For example, the IN operator executes a separate underlying datastore query for every item in the list. The entities returned are a result of the cross-product of all the underlying datastore queries and are de-duplicated. A maximum of 30 datastore queries are allowed for any single GQL query.