Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine datastore for Go does not have != filter

I am messing with GAE for go recently and found it misses fundamental != (not equal to) filter in their datastore API.

https://developers.google.com/appengine/docs/go/datastore/queries#Go_Property_filters

It also has no "OR" condition operand.

Could anyone tell me how could I filter data which is not equal to something?

like image 896
Keyang Avatar asked Aug 14 '14 19:08

Keyang


2 Answers

even the languages that DO have the "!=" filter actually break it down into two inequality filters (one > and one <). Maybe doing the equivalent will solve your problem?

select * from table where param != "test"

becomes equal to

select * from table where param > "test"

merged with the results of

select * from table where param < "test"

not ideal, but given the limitations of the platform... I think it's your only choice.

like image 196
Patrice Avatar answered Sep 25 '22 14:09

Patrice


From the page you linked there's actually an example of how to do that kind of queries.

From Restrictions on queries:

Inequality filters are limited to at most one property

To avoid having to scan the entire index table, the query mechanism relies on all of a query's potential results being adjacent to one another in the index. To satisfy this constraint, a single query may not use inequality comparisons (<, <=, >, >=) on more than one property across all of its filters. For example, the following query is valid, because both inequality filters apply to the same property:

q := datastore.NewQuery("Person").
        Filter("BirthYear >=", minBirthYear).
        Filter("BirthYear <=", maxBirthYear)
like image 44
OneOfOne Avatar answered Sep 25 '22 14:09

OneOfOne