4

I'm trying to get entity from Google DataStore using Admin Console. I use SELECT * FROM User where __key__ = KEY('ag9wYWdhbGd1eS1zdGF0aWNyHAsSBUNhY2hlIhEvYnV0dG9ucy9lZGl0LmdpZgw'). In accordance with GQL docs it should work

KEY('encoded key')

OR

KEY('kind','name'/ID [, 'kind', 'name'/ID...])

but I'm getting

GQL query error ... Encountered "\'ag9wYWdhbGd1eS1zdGF0aWNyHAsSBUNhY2hlIhEvYnV0dG9ucy9lZGl0LmdpZgw\'" at line 1, column 40. 
Was expecting one of: <UNQUOTED_NAME> ... <QUOTED_NAME> ...

But the request SELECT * FROM User where __key__ = KEY(User, 5126463837700096) works fine.

How can I get the entity using string-encoded key?

Patrice
  • 4,641
  • 9
  • 33
  • 43
  • Have you checked that it is a valid encoded key ? – Tim Hoffman Aug 11 '15 at 10:39
  • Yes, I'm using the valid one. Anyway I think it should return the empty row but not the error. – Pavel Bunygin Aug 11 '15 at 11:12
  • What throws me is the error. Specifically Encountered "\'a it's escaping the quote character with \. Are you sure the 'quote character your using is valid ? – Tim Hoffman Aug 11 '15 at 11:34
  • Yes. I tried double quotes, copied quote character, etc... – Pavel Bunygin Aug 11 '15 at 11:47
  • It seems that the parser always expect 2 \ 4 \ 6 parameters for the KEY function and the first one must be without quotes. So the KEY function in console doesn't work with string-encoded key now. It is shame that I cannot find in the console an entity by string-encoded key that used as reference from another entity. – Pavel Bunygin Aug 11 '15 at 11:57
  • It works perfectly fine for me. just checked in my datastore viewer – Sriram Aug 11 '15 at 15:48
  • If by "Google Datastore" you mean *Cloud* Datastore (rather than the datastore of app engine), there are GQL syntax differences, see https://cloud.google.com/datastore/docs/apis/gql/gql_reference . – Alex Martelli Aug 11 '15 at 23:26
  • @AlexMartelli thank you! The documentation for Cloud Datastore GQL is the relevant. As I can see in there is no way to get KEY from string-encoded key in Cloud Datastore GQL. – Pavel Bunygin Aug 12 '15 at 07:25
  • @PavelBunygin, unfortunately I think you're right -- please accept your own answer to mark this Q as closed, *and* if you think it would be a good idea (I personally would!) file a feature request on the public issue tracker at https://code.google.com/p/google-cloud-platform/issues/list to help us possibly schedule such a feature for future delivery -- thanks! – Alex Martelli Aug 14 '15 at 21:18

1 Answers1

2

The Cloud Datastore GQL doesn't support getting KEY from string-encoded key.