class documentation

class grouping_sets(GenericFunction):

View In Hierarchy

Implement the GROUPING SETS grouping operation.

This function is used as part of the GROUP BY of a statement, e.g. _expression.Select.group_by:

stmt = select(
    func.sum(table.c.value), table.c.col_1, table.c.col_2
).group_by(func.grouping_sets(table.c.col_1, table.c.col_2))

In order to group by multiple sets, use the .tuple_ construct:

from sqlalchemy import tuple_

stmt = select(
    func.sum(table.c.value),
    table.c.col_1, table.c.col_2,
    table.c.col_3
).group_by(
    func.grouping_sets(
        tuple_(table.c.col_1, table.c.col_2),
        tuple_(table.c.value, table.c.col_3),
    )
)
New in version 1.2.
Class Variable ​_has​_args Undocumented
Class Variable inherit​_cache Undocumented

Inherited from GenericFunction:

Method __init__ Undocumented
Class Variable ​_register Undocumented
Class Variable coerce​_arguments Undocumented
Instance Variable ​_bind Undocumented
Instance Variable clause​_expr Undocumented
Instance Variable packagenames Undocumented
Instance Variable type Undocumented
_has_args: bool =
inherit_cache: bool =