Please add array_agg function (add a series of PG ARRAY functions)

Issue #3132 resolved
Chris Hofstaedtler
created an issue

PostgreSQL has this nice array_agg function, and it'd be awesome if sqlalchemy would know that it's return type is of ARRAY(type of thing passed in).

BTW, Thanks for making SQLAlchemy!

Comments (14)

  1. Michael Bayer repo owner

    oh you need to pass it through, then this one:

    from sqlalchemy.sql.functions import ReturnTypeFromArgs
    class array_agg(ReturnTypeFromArgs):

    feel free to test the feature there and let me know if _type_from_args() works in the case of ARRAY(something).

  2. Michael Bayer repo owner
    • Added support for the SQL-standard function :class:.array_agg, which automatically returns an :class:.Array of the correct type and supports index / slice operations. As arrays are only supported on Postgresql at the moment, only actually works on Postgresql. fixes #3132

    → <<cset cfae9c2eaf00>>

  3. Sebastian Bank

    Thanks! (with string_agg the call looks a little suprising, right?)

    Maybe the docs can give a hint to wrap array_agg in type_coerce(..., postgresql.ARRAY) if one wants to use contains or other postgres-specific methods.

  4. Michael Bayer repo owner

    we can make that easier but for the moment you can send a list of items as a sqlalchemy.sql.expression.ClauseList. Send a PR to make this more part of the API (see how Selectable.order_by does it).

  5. Log in to comment