Conditional Operators
AMPS contains support for a ternary conditional IF
operator which allows for a Boolean condition to be evaluated to true
or false
, and will return one of the two parameters. The general format of the IF
statement is:
In this example, the BOOLEAN_CONDITIONAL
will be evaluated, and if the result is true, the VALUE_TRUE
value will be returned otherwise the VALUE_FALSE
will be returned.
IF
Conditional expression
Value to return if conditional expression is true
Value to return if conditional expression is false
Evaluate the conditional expression and return one of the two input values based on the results of the expression.
The AMPS expression engine can conditionally evaluate the terms provided to the IF
statement in version 5.3.4 and greater.
In previous versions of AMPS, all expressions provided to the IF
statement were fully evaluated before the IF
statement was evaluated.
For example:
The above example returns a count of the total number of orders that have been placed where the symbol is MSFT and the order contains a quantity more than 500.
The IF
operator can also be used to evaluate results to determine if results are NULL
or NaN
. This is useful for calculating aggregates where some values may be NULL
or NaN
. The NULL
and NaN
values are discussed in more detail in the AMPS Data Types section.
For example:
Last updated