Rules for Order of Evaluation

Teradata Vantageā„¢ SQL Functions, Expressions, and Predicates

brand
Software
Teradata Vantage
prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1145-162K
The following rules apply to evaluation order for conditional expressions:
  • If an expression contains more than one of the same operator, the evaluation precedence is left to right.
  • If an expression contains a combination of logical operators, the order of evaluation is as follows:
    NOT

    AND

    OR

  • Parentheses can be used to establish the desired evaluation precedence.
  • The logical expressions in a conditional expression are not always evaluated left to right.

    Avoid using a conditional expression if its accuracy depends on the order in which its logical expressions are evaluated.

    For example, compare the following two expressions:

       F2/(NULLIF(F1,0)) > 500
       F1 <> 0 AND F2/F1 > 500

    The first expression guarantees exclusion of division by zero.

    The second allows the possibility of error, because the order of its evaluation determines the exclusion of zeros.