[Sqlalchemy-tickets] Issue #4337: aggregate_order_by doesn't accept multiple columns as order_by ar
Brought to you by:
zzzeek
From: Pierre C. <iss...@bi...> - 2018-09-19 16:40:35
|
New issue 4337: aggregate_order_by doesn't accept multiple columns as order_by argument https://bitbucket.org/zzzeek/sqlalchemy/issues/4337/aggregate_order_by-doesnt-accept-multiple Pierre Collet: Hello, The [aggregate_order_by](http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#sqlalchemy.dialects.postgresql.aggregate_order_by) function currently take only 2 arguments (target and order_by) while PostgreSQL (9.6 in my case) totally accept multiple columns in the ORDER BY clause. For instance: ``` #!sql SELECT array_agg(status ORDER BY pk_col1, pk_col2) FROM table_with_pk_on_two_columns GROUP BY col_x; ``` As Mike Bayer emphasized ([here](https://groups.google.com/forum/#!topic/sqlalchemy/A_jfE8hOQHQ) ), it is possible to use a sqlalchemy.sql.expression.ClauseList to specified multiple columns as order_by argument. Example: ``` #!python from sqlalchemy.dialects.postgresql import aggregate_order_by from sqlalchemy import column from sqlalchemy.dialects import postgresql from sqlalchemy.sql.expression import ClauseList elem = aggregate_order_by(column('a'), ClauseList(column('b').asc(), column('c').desc())) print(elem.compile(dialect=postgresql.dialect())) a ORDER BY b ASC, c DESC ``` Still, it would be convenient to make the order_by argument a list (*order_by). Pierre. |