Parentheses in filter syntax

Other than readability is there any use for parentheses in the filter syntax given it’s illegal to
put groups of ANDs within ORs

e.g. you can’t write this A OR (B AND C) so there’s never a functional difference when parens are added to a valid filter?

Hi @richard.scarrott, For performance reasons, we do not allow you to put groups of ANDs within ORs. But, it is permissable to put groups of ORs within ANDs. See this [documentation](http://For performance reasons, we do not allow you to put groups of ANDs within ORs.).

  • We allow ( x AND (y OR z) AND (a OR b) )
  • We allow ( x AND y OR z AND a OR b )
  • We don’t allow ( x OR ( y AND z) OR ( a AND b) )
  • We don’t allow (a AND b) OR (c AND d)

If you omit parentheses, the engine will automatically put the ORs inside parenthesis:

  • ( x AND y OR z AND a OR b ) becomes ( x AND (y OR z) AND (a OR b) )
  • ( x OR y AND z OR a AND b ) becomes ( (x OR y) AND (z OR a) AND b )

Given the potential for confusion, we encourage you to use parenthesis.

Hi @cindy.cullen. Thanks for the quick response. This is what I had gathered from reading the docs, I just wanted to confirm that the grouping via parens is, unlike other query / programming languages, purely for readability; i.e. it cannot impact the logic of a query because groups of ANDs cannot be within ORs meaning ORs are in effect always grouped?

Hi @richard.scarrott, In a sense, yes, they are purely for readability since if you don’t include them, we assume where they should go. We recommend you use parenthesis in case your intentions are different from our default. If your intentions are not in line with our allowable filters, it could help in troubleshooting the issue later.

1 Like