diff options
author | Ilja Everilä <saarni@gmail.com> | 2014-09-10 11:34:33 +0300 |
---|---|---|
committer | Ilja Everilä <saarni@gmail.com> | 2014-09-10 11:34:33 +0300 |
commit | ad82849bbe4ef329129204d02781f737c0c79fcb (patch) | |
tree | 58bb07abaada3c96277933520fefd973c365a103 /lib/sqlalchemy/sql/functions.py | |
parent | a23264e1dc43b1250b9b5de541ff27bd49a2b2c1 (diff) | |
download | sqlalchemy-ad82849bbe4ef329129204d02781f737c0c79fcb.tar.gz |
implementation for <aggregate_fun> FILTER (WHERE ...)
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 7efb1e916..46f3e27dc 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 + Over, BindParameter, AggregateFilter 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 filter(self, *criterion): + """Produce a FILTER clause against this function. + + Used against aggregate functions, + for database backends that support aggregate "FILTER" clause. + + The expression:: + + func.count(1).filter(True) + + is shorthand for:: + + from sqlalchemy import aggregatefilter + aggregatefilter(func.count(1), True) + + See :func:`~.expression.aggregatefilter` for a full description. + + """ + if not criterion: + return self + return AggregateFilter(self, *criterion) + @property def _from_objects(self): return self.clauses._from_objects |