In the GQL reference, it is encouraged to use the IN
keyword with a list of values, and to construct a Key from hand the GQL query
SELECT * FROM MyModel WHERE __key__ = KEY('MyModel', 'my_model_key')
will succeed. However, using the code you would expect to work:
SELECT * FROM MyModel WHERE __key__ IN (KEY('MyModel', 'my_model_key1'),
KEY('MyModel', 'my_model_key2'))
in the Datastore Viewer, there is a complaint of "Invalid GQL query string."
What is the correct way to format such a query?
UPDATE: This is not possible to do with the current SDK. As I note in my comment, when using a list, only a reference (e.g. :1
or :email
) or an int, float, string, boolean or null literal are acceptable list entries.
SECOND UPDATE: I fixed the bug and it is now possible to perform such queries. Fix can be found in Google Code Hosting diff.
PS I know there are more efficient ways to do this in Python (without constructing a GQL query) and using the remote_api, but each call to the remote_api counts against quota. In an environment where quota is not (necessarily) free, quick and dirty queries are very helpful.
WHERE __key__ IN
is invalid GQL? – bossylobster