Relation-valued attribute


group(operand: Relation, attributes: AttrList, as: AttrName) -> Relation


group(suppliers, [:sid, :name, :status], :suppliers)
group(suppliers, [:city], :suppliers, allbut: true)


Summarizes operand by all but the specified attributes and groups the latter under a relation-value attribute as.

This operator could be formally defined as the following shortcut:

def group(operand, attributes, as)
    allbut(operand, attributes),
    as: ->(t){ project(matching(operand, Relation(t)), attributes) })
group(suppliers, [:sid, :name, :status], :suppliers)

This operators supports an ALL BUT variant, through the allbut option. When set to true, the operator keeps specified attributes and groups all remaining ones as a relation-valued attribute.

Implementation notes

This operator does not compile to SQL so far. Contributions are welcome to provide it with a SQL compilation for SQL DBMSs that support this kind of feature (e.g. PostgreSQL with JSON data type)