Boolean Functions and Operators

bool Boolean type
bool or bool Logical disjunction.
bool and bool Logical conjunction.
not bool Logical negation.
= != ?= ?!= < > <= >= Comparison operators
all() Generalized boolean and applied to the set of values.
any() Generalized boolean or applied to the set of values.

type

bool

Booleans - 图1

Booleans - 图2

Booleans - 图3

bool

A boolean type with possible values of true and false.

EdgeQL has case-insensitive keywords and that includes the boolean literals:


1. db>


1. select (True, true, TRUE);


1. {(true, true, true)}


1. db>


1. select (False, false, FALSE);


1. {(false, false, false)}

A boolean value may arise as a result of a logical or comparison operations as well as in and not in:


1. db>


1. select true and 2 < 3;


1. {true}


1. db>


1. select '!' IN {'hello', 'world'};


1. {false}

It is also possible to cast between bool, str, and json:


1. db>


1. select <json>true;


1. {'true'}


1. db>


1. select <bool>'True';


1. {true}

Filter clauses must always evaluate to a boolean:


1. select User
2. filter .name ilike 'alice';

operator

bool or bool

Booleans - 图4

Booleans - 图5

Booleans - 图6

bool or bool -> bool

Logical disjunction.


1. db>


1. select false or true;


1. {true}

operator

bool and bool

Booleans - 图7

Booleans - 图8

Booleans - 图9

bool and bool -> bool

Logical conjunction.


1. db>


1. select false and true;


1. {false}

operator

not bool

Booleans - 图10

Booleans - 图11

Booleans - 图12

not bool -> bool

Logical negation.


1. db>


1. select not false;


1. {true}

The and and or operators are commutative.

The truth tables are as follows:

a b a and b a or b not a
true true true true false
true false false true false
false true false true true
false false false false true

It is important to understand the difference between using and/or vs all()/any(). This difference is in how they handle {}. Both and and or operators apply to the cross-product of their operands. Thus if any of the operands are {}, the result is also {} for and and or.

The all() and any() are generalized to apply to sets of values, including {}. Thus they have the following truth table:

a b all({a, b}) any({a, b})
true true true true
true false false true
{} true true true
{} false false false
false true false true
false false false false
true {} true true
false {} false false
{} {} true false

Since all() and any() apply to sets as a whole, missing values (represented by {}) are just that - missing. They don’t affect the overall result.

To understand the last line in the above truth table it’s useful to remember that all({a, b}) = all(a) and all(b) and any({a, b}) = any(a) or any(b).

For more customized handling of {} the ?? should be used.