!CHAPTER Operators AQL supports a number of operators that can be used in expressions. There are comparison, logical, arithmetic, and the ternary operator. !SUBSUBSECTION Comparison operators Comparison (or relational) operators compare two operands. They can be used with any input data types, and will return a boolean result value. The following comparison operators are supported: - *==* equality - *!=* inequality - *<* less than - *<=* less or equal - *>* greater than - *>=* greater or equal - *IN* test if a value is contained in a list - *NOT IN* test if a value is not contained in a list The *IN* and *NOT IN* operators expect the second operand to be of type list. All other operators accept any data types for the first and second operands. Each of the comparison operators returns a boolean value if the comparison can be evaluated and returns *true* if the comparison evaluates to true, and *false* otherwise. Some examples for comparison operations in AQL: ``` 1 > 0 true != null 45 <= "yikes!" 65 != "65" 65 == 65 1.23 < 1.32 1.5 IN [ 2, 3, 1.5 ] 42 NOT IN [ 17, 40, 50 ] ``` !SUBSUBSECTION Logical operators Logical operators combine two boolean operands in a logical operation and return a boolean result value. The following logical operators are supported: - *&&* logical and operator - *||* logical or operator - *!* logical not/negation operator Some examples for logical operations in AQL: u.age > 15 && u.address.city != "" true || false !u.isInvalid The *&&*, *||*, and *!* operators expect their input operands to be boolean values each. If a non-boolean operand is used, the operation will fail with an error. In case all operands are valid, the result of each logical operator is a boolean value. Both the *&&* and *||* operators use short-circuit evaluation and only evaluate the second operand if the result of the operation cannot be determined by checking the first operand alone. ArangoDB also supports the following alternative forms for the logical operators: - *AND* logical and operator - *OR* logical or operator - *NOT* logical not/negation operator The alternative forms are functionally equivalent to the regular operators. !SUBSUBSECTION Arithmetic operators Arithmetic operators perform an arithmetic operation on two numeric operands. The result of an arithmetic operation is again a numeric value. Operators are supported. AQL supports the following arithmetic operators: - *+* addition - *-* subtraction - \* multiplication - */* division - *%* modulus These operators work with numeric operands only. Invoking any of the operators with non-numeric operands will result in an error. An error will also be raised for some other edge cases as division by zero, numeric over- or underflow etc. If both operands are numeric and the computation result is also valid, the result will be returned as a numeric value. The unary plus and unary minus are supported as well. Some example arithmetic operations: 1 + 1 33 - 99 12.4 * 4.5 13.0 / 0.1 23 % 7 -15 +9.99 !SUBSUBSECTION Ternary operator AQL also supports a ternary operator that can be used for conditional evaluation. The ternary operator expects a boolean condition as its first operand, and it returns the result of the second operand if the condition evaluates to true, and the third operand otherwise. *Examples* u.age > 15 || u.active == true ? u.userId : null !SUBSUBSECTION Range operator AQL supports expressing simple numeric ranges with the *..* operator. This operator can be used to easily iterate over a sequence of numeric values. The *..* operator will produce a list of values in the defined range, with both bounding values included. *Examples* 2010..2013 will produce the following result: [ 2010, 2011, 2012, 2013 ] !SUBSUBSECTION Operator precedence The operator precedence in AQL is similar as in other familiar languages (lowest precedence first): - *? :* ternary operator - *||* logical or - *&&* logical and - *==*, *!=* equality and inequality - *IN* in operator - *<*, *<=*, *>=*, *>* less than, less equal, greater equal, greater than - *+*, *-* addition, subtraction - \*, */*, *%* multiplication, division, modulus - *!*, *+*, *-* logical negation, unary plus, unary minus - [\*] expansion - *()* function call - *.* member access - *[]* indexed value access The parentheses *(* and *)* can be used to enforce a different operator evaluation order.