EdgeQL Tutorial

Sets

Subtopics

There is no NULL value in EdgeDB unlike in many other databases or programming languages. This is deliberate, as NULL scalars create all sorts of problems when interacting with other data and operations.

Instead of the NULL scalar value EdgeDB uses an empty set {} to denote the absence of data. The advantage of using the empty set is that it works exactly like every other set in every way. Its behavior is well-defined and consistent across all operators and functions.

For example, "count" will give the number of elements in an empty set:

Input
Run
Output
Press the 'Run' button to evaluate the input

The EXISTS operator returns false if the set is empty and true otherwise:

Input
Run
Output
Press the 'Run' button to evaluate the input

Usually it is necessary to provide the type of the empty set using a cast, when the type is relevant and cannot be assumed (like in INSERT queries):

Input
Run
Output
Press the 'Run' button to evaluate the input

When an empty set is used as an element-wise operand or element-wise parameter of a function, the result is always an empty set, too (albeit of whatever the return type is). This is because the Cartesian product of the empty set with anything else is still an empty set:

Input
Run
Output
Press the 'Run' button to evaluate the input
Input
Run
Output
Press the 'Run' button to evaluate the input
Input
Run
Output
Press the 'Run' button to evaluate the input

Because of its ability of making any Cartesian product into another empty set, there are some gotchas when an empty set is used where an array or tuple element are expected:

Input
Run
Output
Press the 'Run' button to evaluate the input
Input
Run
Output
Press the 'Run' button to evaluate the input

Typically, if you want to splice 0 or 1 elements into an array the "array_agg" function and concatenation should be used. Try the following example with different values specified for x:

Input
Run
Output
Press the 'Run' button to evaluate the input