问题
I need to group terms in the WHERE clause. For example,
WHERE (param1='foo1' OR param1='foo2') AND (param2='bar1' OR param2='bar2')
But it's giving me a syntax error saying that the parentheses are "unexpected". The actual error is:
GQL query error: Encountered "(" at line 1, column 29. Was expecting one of: "false", "null", "true", <INTEGER>, <DOUBLE>, <SINGLE_QUOTE_STRING>, <DOUBLE_QUOTE_STRING>, <UNQUOTED_NAME>, <QUOTED_NAME>, <NAME_BINDING_SITE>, <POSITION_BINDING_SITE>
So, is there any way for me to run that query?
回答1:
I believe the problem you're facing comes from the OR
operator - GQL doesn't have one, so the conditions you have in the paranthesis are syntactically incorrect.
From the WHERE
row in the Clauses table (emphasis mine):
Limits the result set to those entities that meet one or more conditions. Each condition compares a property of the entity with a value using a comparison operator. If multiple conditions are combined with the AND keyword, then an entity must meet all of the conditions to be returned by the query. GQL does not have an OR operator.
来源:https://stackoverflow.com/questions/49859110/in-google-datastore-gql-how-can-i-group-the-where-terms