Using array_agg around "row" function does not parse correctly
Issue #3729
duplicate
I'm using PostgreSQL and trying to build an array aggregate of tuples by selecting a column like this:
sa.func.array_agg(sa.func.row(User.id, User.name))
This parses as an ugly list of characters.
Putting the "row" on the outside works.
sa.func.row(sa.func.array_agg(User.id), sa.func.array_agg(User.name))
Maybe I'm missing something.
Comments (3)
-
repo owner -
repo owner - changed status to duplicate
Duplicate of #3566.
-
reporter Thanks for the detailed response!
- Log in to comment
the database does not appear to send typing information back to the driver (psycopg2) unless an explicit cast is used:
renders:
the need for the CAST is a driver / psycopg2 / postgresql issue, nothing can be changed for that on this end (except an unconditional CAST in all cases which is heavy-handed). You can make a subclass of ARRAY which renders this cast within the column_expression() method.
The part where the "RECORD" datatype comes back as a string is another thing psycopg2 doesn't know anything about. #3566 proposes to deal with this type. For now, here's a type that will do everything you need: