I can't query GQL for 2 properties only wildcard is working

go, google-app-engine, gql

Solution

The projection queries come with some limitations. In the projection-doc is mentioned that `"Only indexed properties can be projected"`.

The first error message shows exactly that the combined index of `Subject, Comment` doesn't exist yet. You can create the index manually by adding

- kind: comment
  properties:
  - name: Comment
  - name: Subject

to your `index.yaml` in your project root folder. Please have a look at the index spec and projection-doc.

// Error: projections are not supported for the property: __key__

Entity `keys` are returned by the GetAll method. Don't put them in your projection.

keys, err := q.GetAll(c, &people)

I can't post more than 2 links yet, so please look for more details in the datastore reference.

Problem

I store `comment` entity in Datastore and I use `Datastore Viewer` to see stored data. I can do following queries ``` select * from comment select __key__ from comment select Subject from comment select Comment from comment ``` But I can't query ``` select Subject, Comment from comment // Error: The suggested index for this query is: // - kind: comment // properties: // - name: Comment // - name: Subject select __key__, Subject, Comment from comment // Error: projections are not supported for the property: __key__ ``` I can't find any reference why it is wrong. These errors does not tell me much. I have not set any key or index for these entities. Documentation tells following: ``` SELECT [DISTINCT] [* | <property list> | __key__] [FROM <kind>] [WHERE <condition> [AND <condition> ...]] [ORDER BY <property> [ASC | DESC] [, <property> [ASC | DESC] ...]] [LIMIT [<offset>,]<count>] [OFFSET <offset>] <property list> := <property> [, <property> ...] <condition> := <property> {< | <= | > | >= | = | != } <value> <condition> := <property> IN <list> <condition> := ANCESTOR IS <entity or key> <list> := (<value> [, <value> ...]]) ``` `Subject, Comment` - is property list and it valid query. But it is not. I created entity from Go code.

Original source