List Warehouse Query Filter

Select all entries that are not listed.

How to do this:

query = Story.all() query.filter('ID **NOT IN** =', [100,200,..,..]) 
+4
source share
3 answers

There is no way to do this effectively in App Engine. You should simply select everything without this filter and filter out any relevant objects in your code.

+3
source

This is now supported with a GQL query.

Operators' IN 'and'! = 'in the Python runtime, it’s actually implemented in the SDK and translates to multiple requests β€œunder the hood”.

For example, the query "SELECT * FROM People WHERE name IN (" Bob "," Jane ")" is converted to two queries, which is equivalent to running "SELECT * FROM People WHERE name =" Bob "and" SELECT * FROM People "WHERE name = 'Jane' and merging results: Combining multiple clauses multiplies the number of queries required, so the query "SELECT * FROM People WHERE name IN (" Bob "," Jane ") And age! = 25" generates a total of four queries for each of the possible conditions (age less or more than 25, and the name is β€œBob” or β€œJane”), then combines them into a single result set.

source: appengine blog

+2
source

This is an old question, so I'm not sure if the ID is not a key. But to answer this:

 query = Story.all() query.filter('ID **NOT IN** =', [100,200,..,..]) 

... With ndb, you can definitely request items that are in the list. For example, see Docs here for IN and != . Here's how to filter as requested by OP:

 query = Story.filter(Story.id.IN([100,200,..,..]) 

We can even request items that are in the list of duplicate keys:

 def all(user_id): # See if my user_id is associated with any Group. groups_belonged_to = Group.query().filter(user_id == Group.members) print [group.to_dict() for group in belong_to] 

Some reservations:

It says that mentioning that to execute these types of queries, Datastore performs several queries behind the scenes, which (1) may take some time to execute, (2) take longer if you search in duplicate properties, and (3 ) will increase your expenses due to additional operations.

0
source

Source: https://habr.com/ru/post/1303625/


All Articles