Boolean Logic

Boolean Logic

Some clauses, such as WHERE, WHEN, and HAVING, 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

FALSE

FALSE

FALSE

FALSE

TRUE

TRUE

TRUE

TRUE

FALSE

TRUE

FALSE

TRUE

NULL

FALSE

NULL

NULL

TRUE

NULL

NULL

TRUE

NULL

NULL

NULL

NULL

FALSE

MISSING

FALSE

MISSING

TRUE

MISSING

MISSING

TRUE

NULL

MISSING

MISSING

NULL

MISSING

MISSING

MISSING

MISSING

A

not A

FALSE

TRUE

TRUE

FALSE

NULL

NULL

MISSING

MISSING

Comparing null and missing values

Operator

Non-NULL Value

NULL

MISSING

IS NULL

FALSE

TRUE

MISSING

IS NOT NULL

TRUE

FALSE

MISSING

IS MISSING

FALSE

FALSE

TRUE

IS NOT MISSING

TRUE

TRUE

FALSE

IS VALUED

TRUE

FALSE

FALSE

IS NOT VALUED

FALSE

TRUE

TRUE