gcloud python: how to construct query with OR condition

355 views Asked by At

It seems there is no way to construct query with OR condition. Has anyone hit this issue or know when this will be done or any workaround.

What I want to achive something like this with OR:

query = datastore.query(kind='Article',
                         filters=[('url', '=', 'url1'),
                                  ('url', '=', 'url2')]
                       )

But this filter works as AND not OR.

2

There are 2 answers

3
Andrei Volgin On

Python runtime supports "IN" query filter.

Note, however, that this is just a convenience: under the hood, "IN" query is translated into a series of independent queries each looking for one value on the list.

0
Dan McGrath On

OR is not a supported query construct in Google Cloud Datastore.

The current way to achieve this is to construct multiple queries client-side and combine the result sets.

For reference, you should read through the Datastore Queries documentation:

The Datastore currently only supports combining filters with the AND operator. However it's relatively straightforward to create your own OR query by issuing multiple queries and combining the results: