diff options
author | Antti Haapala <antti.haapala@anttipatterns.com> | 2015-01-08 14:32:08 +0200 |
---|---|---|
committer | Antti Haapala <antti.haapala@anttipatterns.com> | 2015-01-08 14:32:08 +0200 |
commit | 1ad2647d2869226fc2f441de4c4e4984806231e0 (patch) | |
tree | bc203c6396bde743affa447d23bf676105da0a69 /lib/sqlalchemy/sql/functions.py | |
parent | b8a8cdd1ff47b5774662f4c61fe49382b967de02 (diff) | |
download | sqlalchemy-pr/156.tar.gz |
Support for the WITHIN GROUP (ORDER BY) clauses (within_group/WithinGroup).pr/156
Diffstat (limited to 'lib/sqlalchemy/sql/functions.py')
-rw-r--r-- | lib/sqlalchemy/sql/functions.py | 24 |
1 files changed, 23 insertions, 1 deletions
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. |