Rohit Krishnan
Rohit Krishnan

Reputation: 63

GAE DATASTORE select __KEY__

When I do the following query to fetch the KEY, I get null. Following is the query:

g_keys = db.GqlQuery("SELECT __KEY__ FROM greeting")

Here are the entities in Greeting DB Object:

Key Write Ops      ID   Key Name author comment     date            source
aglkZXZ-...  11    11  None      None   COMMENT1    2013-02-16      twitter
glkZXZ-...   11    12  None      None   COMMENT2    2013-02-17      facebook

and here is the model definition:

class Greeting(db.Model):

  author = db.UserProperty()
  comment = db.StringProperty(multiline=True)
  source = db.StringProperty(multiline=False)
  date = db.DateTimeProperty(auto_now_add=True)

Please let me know what I am doing wrong.

Thanks in advance

Upvotes: 2

Views: 299

Answers (2)

Alexey Smychagin
Alexey Smychagin

Reputation: 19

I think you should use

__key__ (lowercase)

An example from here https://developers.google.com/appengine/docs/python/datastore/gqlreference?hl=en

SELECT __key__ FROM Person WHERE age = NULL

Upvotes: 0

voscausa
voscausa

Reputation: 11706

For key only queries you have to use the key_only argument.

g_keys = Greeting.all(keys_only=True)

By the way : in your query you use greeting, but your model name is Greeting

Upvotes: 1

Related Questions