Boolean Logic
- reference
Some clauses, such asWHERE
,WHEN
, andHAVING
, require values to be interpreted as Boolean values.
The following rules apply when evaluating these types of clauses:
-
MISSING, NULL, and FALSE are FALSE
-
numbers +0, -0, and NaN are FALSE
-
empty strings, arrays, and objects are FALSE
-
all other values are TRUE
Four-valued logic
In N1QL, Boolean propositions can evaluate to NULL or MISSING (as well as to TRUE and FALSE).
The following table describes how these values relate to the logical operators:
a | b | a AND b | a OR b | NOT a |
---|---|---|---|---|
TRUE |
TRUE |
TRUE |
TRUE |
FALSE |
FALSE |
FALSE |
TRUE |
||
NULL |
NULL |
TRUE |
||
MISSING |
MISSING |
TRUE |
||
FALSE |
TRUE |
FALSE |
TRUE |
TRUE |
FALSE |
FALSE |
FALSE |
||
NULL |
FALSE |
NULL |
||
MISSING |
FALSE |
MISSING |
||
NULL |
TRUE |
NULL |
TRUE |
NULL |
FALSE |
FALSE |
NULL |
||
NULL |
NULL |
NULL |
||
MISSING |
MISSING |
NULL |
||
MISSING |
TRUE |
MISSING |
TRUE |
MISSING |
FALSE |
FALSE |
MISSING |
||
NULL |
MISSING |
NULL |
||
MISSING |
MISSING |
MISSING |