Represent a PostgreSQL aggregate order by expression. 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
| 42 | |
| 43 | |
| 44 | class aggregate_order_by(expression.ColumnElement[_T]): |
| 45 | """Represent a PostgreSQL aggregate order by expression. |
| 46 | |
| 47 | E.g.:: |
| 48 | |
| 49 | from sqlalchemy.dialects.postgresql import aggregate_order_by |
| 50 | |
| 51 | expr = func.array_agg(aggregate_order_by(table.c.a, table.c.b.desc())) |
| 52 | stmt = select(expr) |
| 53 | |
| 54 | would represent the expression: |
| 55 | |
| 56 | .. sourcecode:: sql |
| 57 | |
| 58 | SELECT array_agg(a ORDER BY b DESC) FROM table; |
| 59 | |
| 60 | Similarly:: |
| 61 | |
| 62 | expr = func.string_agg( |
| 63 | table.c.a, aggregate_order_by(literal_column("','"), table.c.a) |
| 64 | ) |
| 65 | stmt = select(expr) |
| 66 | |
| 67 | Would represent: |
| 68 | |
| 69 | .. sourcecode:: sql |
| 70 | |
| 71 | SELECT string_agg(a, ',' ORDER BY a) FROM table; |
| 72 | |
| 73 | .. versionchanged:: 1.2.13 - the ORDER BY argument may be multiple terms |
| 74 | |
| 75 | .. seealso:: |
| 76 | |
| 77 | :class:`_functions.array_agg` |
| 78 | |
| 79 | """ |
| 80 | |
| 81 | __visit_name__ = "aggregate_order_by" |
| 82 | |
| 83 | stringify_dialect = "postgresql" |
| 84 | _traverse_internals: _TraverseInternalsType = [ |
| 85 | ("target", InternalTraversal.dp_clauseelement), |
| 86 | ("type", InternalTraversal.dp_type), |
| 87 | ("order_by", InternalTraversal.dp_clauseelement), |
| 88 | ] |
| 89 | |
| 90 | @overload |
| 91 | def __init__( |
| 92 | self, |
| 93 | target: ColumnElement[_T], |
| 94 | *order_by: _ColumnExpressionArgument[Any], |
| 95 | ): ... |
| 96 | |
| 97 | @overload |
| 98 | def __init__( |
| 99 | self, |
| 100 | target: _ColumnExpressionArgument[_T], |
| 101 | *order_by: _ColumnExpressionArgument[Any], |
no outgoing calls