GQL forbade literal error, google datastore

I am trying to use GQL to get some data from a data warehouse.

When I execute a SELECT * FROM Kind query, it works, and I return the data.

However, when I try:

 SELECT * FROM kind where num < 1234 

I get an invalid literal error.

I even tried to do this using quotes:

 SELECT * FROM kind where num < '1234' 

but I get the same error.

Has anyone come across this before?

Here is the code:

 Query<Entity> query = Query.gqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM " + kind + " WHERE num < '100'" ).build(); QueryResults<Entity> results = datastore.run(query); while (results.hasNext()) { Entity result = results.next(); myList.add(result.getString("num")); 
+5
source share
1 answer

You need to bind the query parameter, not just add it to the query.

 Query<Entity> query = Query.gqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM " + kind + " WHERE num < @num") .setBinding("num", 100) .build(); QueryResults<Entity> results = datastore.run(query); while (results.hasNext()) { Entity result = results.next(); myList.add(result.getString("num")); ... 
+3
source

All Articles