Friday, February 26, 2010

, and ,! operators in query ranges


If a query range value is "A,B" it will be translated into the SQL expression (ItemId='A') OR (ItemId='B'), so both items with ID A and B will be selected. If a query range is "!A" than it will be translated into SQL expression NOT (ItemId='A'), so items with ID not equal to A will be selected. But, if a query range is "A,!B" it will be translated not into (ItemId='A') OR NOT (ItemId='B') as it seems to be correct. It will be translated into (ItemId='A') AND NOT (ItemId='B'). Despite that such behavior looks strange it seems to be a feature, not a bug. So it is just better to understand "," and ",!" as different operators - OR and AND NOT.

4 comments:

  1. (ItemId='A') OR NOT (ItemId='B') would select every item, which is not relevant.

    Another example 100..102,!101 will select 100 and 102, which is ok!

    ReplyDelete
  2. Yes, that's why I think it is a feature. However it seems to be a little bit strange. May be mostly because the "," operator is not commutative as we used to - "!A, B" is not the same as "B, !A".

    ReplyDelete