在 GQL 中编写 IN 子句的替代方法
Alternative way to write IN clause in 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", "=", "<", "<=", ">", ">=", ".", "("
并且所有列都已编入索引。
谢谢
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
如何在 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", "=", "<", "<=", ">", ">=", ".", "("
并且所有列都已编入索引。
谢谢
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