Google App Engine的Go语言数据存储库(datastore)没有!=(不等于)过滤器。

huangapple go评论89阅读模式
英文:

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

问题

最近我在使用 GAE 的 go 语言版本,并发现它的数据存储 API 中缺少基本的 "!="(不等于)过滤器。

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

它也没有 "OR" 条件操作符。

有人可以告诉我如何筛选不等于某个值的数据吗?

英文:

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?

答案1

得分: 6

即使那些具有"!="过滤器的语言实际上也将其分解为两个不等式过滤器(一个大于号和一个小于号)。也许采取相同的方法可以解决你的问题?

select * from table where param != "test"

等同于

select * from table where param > "test"

再与

select * from table where param < "test"

的结果合并

虽然不是理想的解决方案,但考虑到平台的限制...我认为这是你唯一的选择。

英文:

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.

答案2

得分: 3

从你提供的链接页面上,实际上有一个如何执行这种查询的示例。

查询限制中:

> 不等式过滤器仅限于一个属性
>
>>为了避免扫描整个索引表,查询机制依赖于查询的所有潜在结果在索引中相邻。为了满足这个约束条件,单个查询不能在所有过滤器中对多个属性使用不等式比较符(<,<=,>,>=)。例如,以下查询是有效的,因为两个不等式过滤器都应用于同一个属性:

q := datastore.NewQuery(&quot;Person&quot;).
        Filter(&quot;BirthYear &gt;=&quot;, minBirthYear).
        Filter(&quot;BirthYear &lt;=&quot;, maxBirthYear)
英文:

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(&quot;Person&quot;).
        Filter(&quot;BirthYear &gt;=&quot;, minBirthYear).
        Filter(&quot;BirthYear &lt;=&quot;, maxBirthYear)

huangapple
  • 本文由 发表于 2014年8月15日 03:36:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/25316238.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定