from . import types
from .array import ARRAY
+from ...sql import aggregate_order_by as aggregate_order_by_core
from ...sql import coercions
from ...sql import elements
from ...sql import expression
_T = TypeVar("_T", bound=Any)
-class aggregate_order_by(elements.AggregateOrderBy[_T]):
- """Represent an aggregate order by expression.
-
- .. deprecated:: 2.0.X
- The PostgreSQL-specific :class:`aggregate_order_by` is deprecated.
- Please use :func:`sqlalchemy.sql.expression.aggregate_order_by` instead,
- which is now available as core functionality.
-
- E.g.::
-
- from sqlalchemy.dialects.postgresql import aggregate_order_by
-
- expr = func.array_agg(aggregate_order_by(table.c.a, table.c.b.desc()))
- stmt = select(expr)
-
- would represent the expression:
-
- .. sourcecode:: sql
-
- SELECT array_agg(a ORDER BY b DESC) FROM table;
-
- Similarly::
-
- expr = func.string_agg(
- table.c.a, aggregate_order_by(literal_column("','"), table.c.a)
- )
- stmt = select(expr)
-
- Would represent:
-
- .. sourcecode:: sql
-
- SELECT string_agg(a, ',' ORDER BY a) FROM table;
-
- .. versionchanged:: 1.2.13 - the ORDER BY argument may be multiple terms
-
- .. versionchanged:: 2.0.X - moved to core functionality as :func:`sqlalchemy.sql.expression.aggregate_order_by`
-
- .. seealso::
-
- :func:`sqlalchemy.sql.expression.aggregate_order_by`
-
- :class:`_functions.array_agg`
-
- """
+def aggregate_order_by(target: expression.ColumnElement[_T], *order_by: expression.ColumnElement[_T]):
+ return aggregate_order_by_core(target, *order_by)
class ExcludeConstraint(ColumnCollectionConstraint):
"""A table-level EXCLUDE constraint.