MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / group_by

Method group_by

lib/sqlalchemy/orm/query.py:2079–2120  ·  view source on GitHub ↗

Apply one or more GROUP BY criterion to the query and return the newly resulting :class:`_query.Query`. All existing GROUP BY settings can be suppressed by passing ``None`` - this will suppress any GROUP BY configured on mappers as well. .. seealso::

(
        self,
        __first: Union[
            Literal[None, False, _NoArg.NO_ARG],
            _ColumnExpressionOrStrLabelArgument[Any],
        ] = _NoArg.NO_ARG,
        /,
        *clauses: _ColumnExpressionOrStrLabelArgument[Any],
    )

Source from the content-addressed store, hash-verified

2077
2078 @_generative
2079 def group_by(
2080 self,
2081 __first: Union[
2082 Literal[None, False, _NoArg.NO_ARG],
2083 _ColumnExpressionOrStrLabelArgument[Any],
2084 ] = _NoArg.NO_ARG,
2085 /,
2086 *clauses: _ColumnExpressionOrStrLabelArgument[Any],
2087 ) -> Self:
2088 """Apply one or more GROUP BY criterion to the query and return
2089 the newly resulting :class:`_query.Query`.
2090
2091 All existing GROUP BY settings can be suppressed by
2092 passing ``None`` - this will suppress any GROUP BY configured
2093 on mappers as well.
2094
2095 .. seealso::
2096
2097 These sections describe GROUP BY in terms of :term:`2.0 style`
2098 invocation but apply to :class:`_orm.Query` as well:
2099
2100 :ref:`tutorial_group_by_w_aggregates` - in the
2101 :ref:`unified_tutorial`
2102
2103 :ref:`tutorial_order_by_label` - in the :ref:`unified_tutorial`
2104
2105 :meth:`_sql.Select.group_by` - v2 equivalent method.
2106
2107 """
2108
2109 for assertion in (self._no_statement_condition, self._no_limit_offset):
2110 assertion("group_by")
2111
2112 if not clauses and (__first is None or __first is False):
2113 self._group_by_clauses = ()
2114 elif __first is not _NoArg.NO_ARG:
2115 criterion = tuple(
2116 coercions.expect(roles.GroupByRole, clause)
2117 for clause in (__first,) + clauses
2118 )
2119 self._group_by_clauses += criterion
2120 return self
2121
2122 @_generative
2123 @_assertions(_no_statement_condition, _no_limit_offset)

Callers 15

_table_options_queryMethod · 0.45
_constraint_queryMethod · 0.45
_index_queryMethod · 0.45
_enum_queryMethod · 0.45
_domain_queryMethod · 0.45
test_keys_anon_labelsMethod · 0.45
test_exists_methodMethod · 0.45
test_orderby_groupbyMethod · 0.45
test_compound_selectsMethod · 0.45

Calls

no outgoing calls