4
votes

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?

1
Have you checked that it is a valid encoded key ? - Tim Hoffman
Yes, I'm using the valid one. Anyway I think it should return the empty row but not the error. - Pavel Bunygin
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
Yes. I tried double quotes, copied quote character, etc... - Pavel Bunygin
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

1 Answers

2
votes

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