When MapInfo Pro evaluates expressions it needs to know which components of an expression to evaluate first. This is called precedence. By convention, certain operators are assigned different levels of precedence. Those with the highest level are evaluated first. The following table lists MapInfo Pro's operators in the order in which they are evaluated. Exponentiation evaluates from the right. This affects expressions with multiple exponents: 2 ^ -3 ^ -4 = 2 ^ ( - (3 ^ (-4)))
Operators at the same level of precedence are evaluated from left to right.
Highest Priority: | Parenthesis |
Exponentiation | |
Negation | |
Multiplication, Division | |
Addition, Subtraction | |
Geographic operators, Comparison operators | |
Not | |
And | |
Lowest Priority: | Or |
For example, the expression 3+4*2 produces a result of 11. That is because multiplication has a higher precedence than addition and is performed first, in effect:
3+4*2=
3+8=
11
We can add parenthesis to force MapInfo Pro to do the addition first:
(3+4)*2=
7*2=
14
Now consider expression 60, which is intended to select all records July or September of 1989.
- year(RECEIVED)=89 and month(RECEIVED)=7 or month(RECEIVED)=9
Because "and" has higher precedence than "or", MapInfo Pro treats this expression as though "year(RECEIVED)=89 and month(RECEIVED)=7" was enclosed in parentheses.
- (year(RECEIVED)=89 and month(RECEIVED)=7) or month(RECEIVED)=9
In this case, any record for July of 89 or for September of any year would be selected. That is probably not what you want. However, by adding parentheses to the second expression, you can get this:
- year(RECEIVED)=89 and (month(RECEIVED)=7 or month(RECEIVED)=9)
In this expression, the parentheses tell MapInfo Pro that "month(RECEIVED)=7" and "month(RECEIVED)=9" are alternatives in the second clause of the expression. MapInfo Pro treats this the same as it treats number 53 above.
See Also: