Rules for Order of Evaluation - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantageā„¢
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.