views:

757

answers:

2

How do I write a query against the entity key using GQL in the Google App Engine Data Viewer ?

In the viewer, the first column (Id/Name) displays as name=_1, in the detail view it shows the key as

Decoded entity key: Programme: name=_1
Entity key: agtzcG9................... 

This query does not work:

SELECT * FROM Programme where name = '_1'
+5  A: 

You can use the entity's key to retrieve it:

SELECT * FROM Programme where __key__ = KEY('agtzcG9...................')

And, you should be able to query using the name similarly:

SELECT * FORM Programme where __key__ = KEY('Programme', '_1')
Adam Crossland
Argh, no. This is a _huge_ waste of time and resources.
Nick Johnson
@Nick: but in the Admin Console, there is probably no better way.
Thilo
Sorry, my mistake. :/
Nick Johnson
is it possible to query by Id instead of Key?
tensaix2j
+1  A: 

You don't need to query to get an entity by key at all - you can simply fetch the entity by its key. In Python, you can do this with MyModel.get_by_key_name('_1'). This is 3 to 5 times faster than Adam's suggestion of using a query.

Nick Johnson
It wasn't my suggestion, Nick, I was just trying to help him make his query work. I think that he is trying to view things in the admin console data viewer.
Adam Crossland
@Nick+Adam: yes, I was trying to review some data in the admin console.
Thilo