MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / WithinGroup

Class WithinGroup

lib/sqlalchemy/sql/elements.py:4357–4462  ·  view source on GitHub ↗

Represent a WITHIN GROUP (ORDER BY) clause. This is a special operator against so-called "ordered set aggregate" and "hypothetical set aggregate" functions, including ``percentile_cont()``, ``rank()``, ``dense_rank()``, etc. It's supported only by certain database backends, suc

Source from the content-addressed store, hash-verified

4355
4356
4357class WithinGroup(ColumnElement[_T]):
4358 """Represent a WITHIN GROUP (ORDER BY) clause.
4359
4360 This is a special operator against so-called
4361 "ordered set aggregate" and "hypothetical
4362 set aggregate" functions, including ``percentile_cont()``,
4363 ``rank()``, ``dense_rank()``, etc.
4364
4365 It's supported only by certain database backends, such as PostgreSQL,
4366 Oracle Database and MS SQL Server.
4367
4368 The :class:`.WithinGroup` construct extracts its type from the
4369 method :meth:`.FunctionElement.within_group_type`. If this returns
4370 ``None``, the function's ``.type`` is used.
4371
4372 """
4373
4374 __visit_name__ = "withingroup"
4375
4376 _traverse_internals: _TraverseInternalsType = [
4377 ("element", InternalTraversal.dp_clauseelement),
4378 ("order_by", InternalTraversal.dp_clauseelement),
4379 ]
4380
4381 order_by: Optional[ClauseList] = None
4382
4383 def __init__(
4384 self,
4385 element: Union[FunctionElement[_T], FunctionFilter[_T]],
4386 *order_by: _ColumnExpressionArgument[Any],
4387 ):
4388 self.element = element
4389 if order_by is not None:
4390 self.order_by = ClauseList(
4391 *util.to_list(order_by), _literal_as_text_role=roles.ByOfRole
4392 )
4393
4394 def __reduce__(self):
4395 return self.__class__, (self.element,) + (
4396 tuple(self.order_by) if self.order_by is not None else ()
4397 )
4398
4399 def over(
4400 self,
4401 *,
4402 partition_by: Optional[_ByArgument] = None,
4403 order_by: Optional[_ByArgument] = None,
4404 rows: Optional[typing_Tuple[Optional[int], Optional[int]]] = None,
4405 range_: Optional[typing_Tuple[Optional[int], Optional[int]]] = None,
4406 groups: Optional[typing_Tuple[Optional[int], Optional[int]]] = None,
4407 ) -> Over[_T]:
4408 """Produce an OVER clause against this :class:`.WithinGroup`
4409 construct.
4410
4411 This function has the same signature as that of
4412 :meth:`.FunctionElement.over`.
4413
4414 """

Callers 3

within_groupMethod · 0.85
within_groupMethod · 0.85
within_groupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected