Condition Expression

On This Page

Overview

A condition expression is an expression that defines a condition for executing an operation, based on the attributes of the items against which the expression is evaluated. For example, the NoSQL Web API UpdateItem operation receives an optional condition-expression request parameter (ConditionExpression) that defines a condition that determines whether to update the item or which update expression to use in the case of an if-then-else update.

Arrays Support
In the current release, the support for array attributes and the use of array operators and functions in expressions is restricted to the web APIs.

Filter Expression

For operations that retrieve existing item attributes, the condition expression acts as a filter expression that restricts the operation to a subset of items to be returned in the response. For example, the NoSQL Web API GetItems operation receives an optional FilterExpression request parameter that defines a condition that determines which items to return.

Syntax

"CONDITION [LOGICAL-OPERATOR CONDITION ...]"

A condition expression is a Boolean expression that is composed of one or more Boolean expressions (CONDITION) that are connected using a binary logical operator (LOGICAL-OPERATOR) — AND or OR. The unary logical operator NOT can be used to negate a condition.
A condition can optionally be enclosed within parentheses.

Note
If a condition within the expression references an attribute that is not set in the evaluated item, the condition fails (evaluates to false). The result of the entire condition expression depends on the expression's overall logic.

Examples

  1. Check for "Car" products with less than 15 known bugs:

    "(bugs < 15) AND starts(Product_Name, 'Car')"
    
  2. Check for 40-year-old people whose first names are "John" and are not residents of Arizona or Massachusetts:

    "(age == 40) and (firstName == 'John') and NOT(State IN ('AZ','MA'))"
    
  3. Check whether the value of the third element in an "intArray" array attribute equals the sum of the first two elements in the array:

    "intArray[2] == intArray[0] + intArray[1]"
    
  4. Check whether the value of the first or second elements of an "arr" array attribute is 7:

    "arr[0]==7 OR arr[1]==7"
    
  5. Check for released adult prisoners who haven't reported to their parole officer:

    "(age > 18) AND isReleased==true AND reported==false"
    
  6. Check whether the first or last five elements of a "ctrs" array contain the highest value:

    "max(ctrs[0..4]) > max(ctrs[5..9])"
    

See Also