Boolean type | |
Evaluates true if either boolean is true. | |
Evaluates true if both booleans are true. | |
Logically negates a given boolean value. | |
Comparison operators | |
Returns true if none of the values in the given set are false. | |
Returns true if any of the values in the given set is true. | |
assert() (added in 3.0) |
Checks that the input bool is true. |
A boolean type of either true
or false
.
EdgeQL has case-insensitive keywords and that includes the boolean literals:
db>
select (True, true, TRUE);
{(true, true, true)}
db>
select (False, false, FALSE);
{(false, false, false)}
These basic operators will always result in a boolean value:
Some examples:
db>
select true and 2 < 3;
{true}
db>
select '!' IN {'hello', 'world'};
{false}
It’s possible to get a boolean by casting a str
or
json
value into it:
db>
select <bool>('true');
{true}
db>
select <bool>to_json('false');
{false}
Filter clauses must always evaluate to a boolean:
select User
filter .name ilike 'alice';
The and
and or
operators are commutative.
The truth tables are as follows:
a |
b |
a |
a |
|
---|---|---|---|---|
true |
true |
true |
true |
false |
true |
false |
false |
true |
false |
false |
true |
false |
true |
true |
false |
false |
false |
false |
true |
The operators and
/or
and the functions all()
/any()
differ in the way they handle an empty set ({}
). Both and
and or
operators apply to the cross-product of their operands. If either operand is
an empty set, the result will also be an empty set. For example:
db>
select {true, false} and <bool>{};
{}
db>
select true and <bool>{};
{}
Operating on an empty set with all()
/any()
does not
return an empty set:
db>
select all(<bool>{});
{true}
db>
select any(<bool>{});
{false}
all()
returns true
because the empty set contains no false
values.
any()
returns false
because the empty set contains no
true values.
The all()
and any()
functions are generalized to apply to
sets of values, including {}
. Thus they have the following truth
table:
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 {}
, use the ??
operator.