GQL Query with __key__ in List of KEYs

Posted by bossylobster on Stack Overflow See other posts from Stack Overflow or by bossylobster
Published on 2011-11-29T01:47:44Z Indexed on 2011/11/29 1:49 UTC
Read the original article Hit count: 204

Filed under:

In the GQL reference [1], 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?

[1] http://code.google.com/appengine/docs/python/datastore/gqlreference.html

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.

© Stack Overflow or respective owner

Related posts about google-app-engine