A boolean type with possible values of true
and 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)}
A boolean value may arise as a result of a logical or comparison
operations as well as in
and not in
:
db>
select true and 2 < 3;
{true}
db>
select '!' IN {'hello', 'world'};
{false}
It is also possible to cast
between
bool
, str
, and json
:
db>
select <json>true;
{'true'}
db>
select <bool>'True';
{true}
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 |
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 |
|
|
---|---|---|---|
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.