Datastore Query Viewer - Ancestor GQL

389 views
Skip to first unread message

Daniel Young

unread,
Oct 9, 2015, 12:04:44 PM10/9/15
to Google App Engine
I found like many others being redirected to the the new datastore. My trusty GQL ancestor query doesn't seem to work anymore

select * from <<Kind>> where ancestor is key('Kind', ID)

Is there a workaround, is this considered a bug?

Patrice (Cloud Platform Support)

unread,
Oct 9, 2015, 5:57:02 PM10/9/15
to Google App Engine
Hi Daniel.

What do you mean by "doesn't work"? Is there an error when you run it? or does it run and produces no results? 

As far as I know GQL didn't change between old and new console, so it should still behave as expected. I'll try to reproduce to see what's happening. In the meantime, if you have an error, including it here would be helpful :).

Cheers!

Daniel Young

unread,
Oct 11, 2015, 9:07:26 PM10/11/15
to Google App Engine
Sorry for the vagueness - here is my query that still returns the entity in the legacy Datastore viewer in the By GQL field 

SELECT * FROM Kind where ancestor is key('Kind', 12344567...)

and in the new viewer I get this GQL error

GQL query error
'SELECT * FROM Kind where ancestor is key('Kind', 12344567...) LIMIT 50': Encountered "ancestor" at line 1, column 32. Was expecting one of: <UNQUOTED_NAME> ... <QUOTED_NAME> ... <NAME_BINDING_SITE> ... <POSITION_BINDING_SITE> ... <SINGLE_QUOTE_STRING> ... <DOUBLE_QUOTE_STRING> ... <INTEGER> ... <DOUBLE> ... "true" ... "false" ... "null" 

Anastasios Hatzis

unread,
Oct 12, 2015, 3:19:24 AM10/12/15
to Google App Engine
I wanted to check this out myself, but for some reason I don't have GQL support in new console of my apps.

But maybe, the new console uses the Datastore GQL, while the old version used the Python GQL. According to the docs there are a few differences, the ancestor expression is one of them:

Python GQL expression ANCESTOR IS <entity-or-key-value> is represented in Datastore GQL as the more general expression __key__ HAS ANCESTOR <key-value>


I hope this is the reason and I didn't just add more to the confusion though. And I hope I will get the GQL options too in the Query page.

Patrice (Cloud Platform Support)

unread,
Oct 12, 2015, 11:52:10 AM10/12/15
to Google App Engine
Hi guys,

So yes, Anastasios' solution should be the correct one. Can you confirm if it does work David?

Anastasios, when you go to "Storage -> Cloud Datastore -> Query", you should have a dropdown on "query by kind" which can switch to "Query using GQL".

Cheers

Anastasios Hatzis

unread,
Oct 12, 2015, 1:04:03 PM10/12/15
to Google App Engine
Daniel, this is an example that worked in my case:

SELECT * FROM MyChildKind WHERE __key__ HAS ANCESTOR KEY(MyParentKind, "this_name")


Patrice, thank you, I've found the dropdown "query by kind" in one of three apps, the other two don't have the same dropdown. Probably this feature is still in deployment. I will contact support if it isn't added in the near future.

Cheerio

Daniel Young

unread,
Oct 12, 2015, 1:34:00 PM10/12/15
to Google App Engine

Anastasios - thank you this works for an ancestor query for me

SELECT * FROM MyChildKind WHERE __key__ HAS ANCESTOR KEY(MyParentKind, "this_name")

Much appreciated.

DY
Reply all
Reply to author
Forward
0 new messages