Not this question (where the problem is using ANCESTOR =
instead of ANCESTOR IS
)
I used ANCESTOR IS
properly:
SELECT DISTINCT batch_no
FROM Entry
WHERE ANCESTOR IS KEY('ag1kZXZ-dHRiLXRhbWVychkLEgdCcmV3ZXJ5IgxCUi1USEVSRURQRUEM')
But I still got an error:
Identifier is a reserved keyword as symbol ANCESTOR
Why is that?
EDIT
I'm getting the same error later years later as I try to update from db
to ndb
, but I think it's a different reason...
Identifier is a reserved keyword at symbol ANCESTOR
But in this case my query is not using DISTINCT
SELECT *
FROM Balance
WHERE ANCESTOR IS KEY('...')
AND first_balance_ever = TRUE
ORDER BY created_date
So I'm not sure the problem here, maybe it's ANCESTOR
related, maybe it's KEY(...)
related...
In this case, DISTINCT
was causing the problem. Remove it and the query works as expected.
I think the query is implicitly projecting only that property you DISTINCT
on, so you cannot access the key/ancestor for ANCESTOR IS
. (But is this true even if you use SELECT *
?)
But the error message is not very clear...
Google describes that DISTINCT
is experimental. Mentions this in db.Query
documentation:
Grouping(experimental)
Projection queries can use the
distinct
keyword to ensure that only completely unique results will be returned in a result set. This will only return the first result for entities which have the same values for the properties that are being projected.
And in the GQL documentation
The optional
DISTINCT
(experimental) clause specifies that only completely unique results will be returned in a result set. This will only return the first result for entities which have the same values for the properties that are being projected.