Logical operators
FQL supports symbolic and keyword forms of the logical operators:
&&orand||oror!ornot
The paired forms have the same behavior.
Truth values for and and or
Binary and and or evaluate each operand according to its Boolean representation:
noneis false.- Booleans keep their value.
- Numeric zero is false; other numbers are true.
- A zero Duration or DateTime is false; other temporal values are true.
- An empty String is false; other strings are true.
- Arrays and objects are true, even when empty.
- Binary and host values are true.
The conversion is used only to decide control flow. and and or return one of their original operands rather than an automatically converted Boolean.
Logical and
and evaluates the left operand first. If it is false, the expression returns that operand without evaluating the right operand. Otherwise, it evaluates and returns the right operand.
This returns "Ada" because the left operand is true.
Logical or
or evaluates the left operand first. If it is true, the expression returns that operand without evaluating the right operand. Otherwise, it evaluates and returns the right operand.
?? when only none should select the fallback. Unlike or, none coalescing preserves false, zero, and empty strings.
See none-Coalescing Operator for the fallback semantics and examples.
Logical not
Unary ! and not accept only Boolean operands and always return a Boolean.
Other types produce an operator-oriented runtime error:
Use to_bool(value) when explicit Boolean conversion is intended.
!!value with to_bool(value).
Short-circuit evaluation
The right side of and is evaluated only when the left side is true. The right side of or is evaluated only when the left side is false.
Subqueries are an exception to this source-level model. Query planning may evaluate a subquery operand before the logical operator, so short-circuiting should not be used to suppress a subquery’s execution.
Result values
! and not always return a Boolean. and and or return an operand, so their result may have any FQL type.
When a strict Boolean result is required from a binary logical expression, pass the result to to_bool.