在GQL中编写IN子句的替代方法

时间:2017-07-10 10:45:11

标签: google-cloud-datastore google-cloud-platform gql

如何在GQL中编写以下查询

  

select * from test WHERE lid = 1234 AND status IN(1,7,8)order by sent_datetime DESC

执行上述查询时出现异常:GQL query error: Encountered "IN" at line 1, column 46. Was expecting one of: "contains", "has", "is", "=", "<", "<=", ">", ">=", ".", "("

所有列都已编入索引。

由于

1 个答案:

答案 0 :(得分:3)

IN是某些客户端库的一项功能,并不是服务器GQL语言的严格组成部分。通过为IN子句和重复数据删除结果中的每个值发出查询,您可以执行与客户端库相同的操作来模拟此功能。

所以这个:

select * from test WHERE lid=1234 AND status IN (1,7,8) order by sent_datetime DESC

会成为这些:

select * from test WHERE lid=1234 AND status = 1 order by sent_datetime DESC
select * from test WHERE lid=1234 AND status = 7 order by sent_datetime DESC
select * from test WHERE lid=1234 AND status = 8 order by sent_datetime DESC