← Back to context

Comment by ldb

7 years ago

> any element-wise operation on an empty set is, likewise, an empty set

Does this mean that "SELECT 1 + {}" gives "{}"?

Correct.

  • Assume I have a table "Actors" with a column "age" and for some of the records the age is not set (an empty set). Does this mean that "SELECT SUM(age) FROM Actors;" gives "{}" or do you implement a special logic for empty-set summation when used in connection with aggregation (like SQL does)?

    • Aggregate functions in EdgeDB have an "initial value", which, for `sum()` is defined as zero. Other aggregates, like `avg()` are not defined for empty sets (you cannot divide by 0), so an error is thrown in this case.

      2 replies →

    • The sum of an empty set is, in fact, 0 (the identity for addition).

      The generalized conjuction (we have a function called "all" for that) of an empty set is True (the identity for conjunction).

      The generalized disjuction (we have a function called "any" for that) of an empty set is False (the identity for disjunction).

      All of the above "sum", "all", and "any" are basically aggregate functions that operate on sets as a whole.

      There is no special logic that you wouldn't get from considering these operations generalized for a set.

      9 replies →