Light
Dark
System
1.0latest

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
bool

A boolean type with possible values of true and false.

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

Copy
db> 
select (True, true, TRUE);
{(true, true, true)}
Copy
db> 
select (False, false, FALSE);
{(false, false, false)}

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

Copy
db> 
select true and 2 < 3;
{true}
Copy
db> 
select '!' IN {'hello', 'world'};
{false}

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

Copy
db> 
select <json>true;
{'true'}
Copy
db> 
select <bool>'True';
{true}

Filter clauses must always evaluate to a boolean:

Copy
select User
filter .name ilike 'alice';
operator
bool or bool
bool or bool -> bool

Logical disjunction.

Copy
db> 
select false or true;
{true}
operator
bool and bool
bool and bool -> bool

Logical conjunction.

Copy
db> 
select false and true;
{false}
operator
not bool
not bool -> bool

Logical negation.

Copy
db> 
select not false;
{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.

Light
Dark
System