From 1ad2647d2869226fc2f441de4c4e4984806231e0 Mon Sep 17 00:00:00 2001 From: Antti Haapala Date: Thu, 8 Jan 2015 14:32:08 +0200 Subject: Support for the WITHIN GROUP (ORDER BY) clauses (within_group/WithinGroup). --- lib/sqlalchemy/sql/functions.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql/functions.py') diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index 9280c7d60..f61ebfcd0 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -12,7 +12,7 @@ from . import sqltypes, schema from .base import Executable, ColumnCollection from .elements import ClauseList, Cast, Extract, _literal_as_binds, \ literal_column, _type_from_args, ColumnElement, _clone,\ - Over, BindParameter, FunctionFilter + Over, BindParameter, FunctionFilter, WithinGroup from .selectable import FromClause, Select, Alias from . import operators @@ -116,6 +116,28 @@ class FunctionElement(Executable, ColumnElement, FromClause): """ return Over(self, partition_by=partition_by, order_by=order_by) + def within_group(self, order_by=None): + """Produce a WITHIN GROUP clause against this function. + + Used against ordered-set and hypothetical-set aggregates + within groups. + + The expression:: + + func.percentile_disc(0.25).within_group(order_by='x') + + is shorthand for:: + + from sqlalchemy import within_group + within_group(func.percentile_disc(0.25), order_by='x') + + See :func:`~.expression.within_group` for a full description. + + .. versionadded:: 1.0 + + """ + return WithinGroup(self, order_by=order_by) + def filter(self, *criterion): """Produce a FILTER clause against this function. -- cgit v1.2.1