from .sql import (
- aggregatefilter,
alias,
and_,
asc,
extract,
false,
func,
+ funcfilter,
insert,
intersect,
intersect_all,
Selectable,
TableClause,
Update,
- aggregatefilter,
alias,
and_,
asc,
false,
False_,
func,
+ funcfilter,
insert,
intersect,
intersect_all,
)
)
- def visit_aggregatefilter(self, aggregatefilter, **kwargs):
+ def visit_funcfilter(self, funcfilter, **kwargs):
return "%s FILTER (WHERE %s)" % (
- aggregatefilter.func._compiler_dispatch(self, **kwargs),
- aggregatefilter.criterion._compiler_dispatch(self, **kwargs)
+ funcfilter.func._compiler_dispatch(self, **kwargs),
+ funcfilter.criterion._compiler_dispatch(self, **kwargs)
)
def visit_extract(self, extract, **kwargs):
))
-class AggregateFilter(ColumnElement):
- """Represent an aggregate FILTER clause.
+class FunctionFilter(ColumnElement):
+ """Represent a function FILTER clause.
- This is a special operator against aggregate functions,
+ This is a special operator against aggregate and window functions,
which controls which rows are passed to it.
It's supported only by certain database backends.
"""
- __visit_name__ = 'aggregatefilter'
+ __visit_name__ = 'funcfilter'
criterion = None
def __init__(self, func, *criterion):
- """Produce an :class:`.AggregateFilter` object against a function.
+ """Produce an :class:`.FunctionFilter` object against a function.
- Used against aggregate functions,
- for database backends that support aggregate "FILTER" clause.
+ Used against aggregate and window functions,
+ for database backends that support the "FILTER" clause.
E.g.::
- from sqlalchemy import aggregatefilter
- aggregatefilter(func.count(1), MyClass.name == 'some name')
+ from sqlalchemy import funcfilter
+ funcfilter(func.count(1), MyClass.name == 'some name')
Would produce "COUNT(1) FILTER (WHERE myclass.name = 'some name')".
True_, False_, BinaryExpression, Tuple, TypeClause, Extract, \
Grouping, not_, \
collate, literal_column, between,\
- literal, outparam, type_coerce, ClauseList, AggregateFilter
+ literal, outparam, type_coerce, ClauseList, FunctionFilter
from .elements import SavepointClause, RollbackToSavepointClause, \
ReleaseSavepointClause
insert = public_factory(Insert, ".expression.insert")
update = public_factory(Update, ".expression.update")
delete = public_factory(Delete, ".expression.delete")
-aggregatefilter = public_factory(
- AggregateFilter, ".expression.aggregatefilter")
+funcfilter = public_factory(
+ FunctionFilter, ".expression.funcfilter")
# internal functions still being called from tests and the ORM,
from .base import Executable, ColumnCollection
from .elements import ClauseList, Cast, Extract, _literal_as_binds, \
literal_column, _type_from_args, ColumnElement, _clone,\
- Over, BindParameter, AggregateFilter
+ Over, BindParameter, FunctionFilter
from .selectable import FromClause, Select, Alias
from . import operators
def filter(self, *criterion):
"""Produce a FILTER clause against this function.
- Used against aggregate functions,
- for database backends that support aggregate "FILTER" clause.
+ Used against aggregate and window functions,
+ for database backends that support the "FILTER" clause.
The expression::
is shorthand for::
- from sqlalchemy import aggregatefilter
- aggregatefilter(func.count(1), True)
+ from sqlalchemy import funcfilter
+ funcfilter(func.count(1), True)
- See :func:`~.expression.aggregatefilter` for a full description.
+ See :func:`~.expression.funcfilter` for a full description.
"""
if not criterion:
return self
- return AggregateFilter(self, *criterion)
+ return FunctionFilter(self, *criterion)
@property
def _from_objects(self):
"(ORDER BY mytable.myid + :myid_1) AS anon_1 FROM mytable"
)
- def test_aggregate_filter(self):
+ def test_funcfilter(self):
self.assert_compile(
func.count(1).filter(),
"count(:param_1)"
expr2 = CloningVisitor().traverse(expr)
assert str(expr) == str(expr2)
- def test_aggregatefilter(self):
+ def test_funcfilter(self):
expr = func.count(1).filter(t1.c.col1 > 1)
expr2 = CloningVisitor().traverse(expr)
assert str(expr) == str(expr2)