add array arg to select().distinct(), query().distinct()

Issue #1069 resolved
Mike Bayer repo owner created an issue

this is to fully support PG's DISTINCT ON, as in http://www.postgresql.org/docs/8.2/interactive/sql-select.html#SQL-DISTINCT . add unit tests.

We cannot use the standalone distinct() for this since it is not a separate column expression.

Comments (8)

  1. Former user Account Deleted

    SQL for DISTINCT ON seem to be in postgresql dialect adapter already for 0.5.5/0.6, so it seems just a matter of adding a few lines to Query.distinct.

    Just found myself in need of this feature, so wrote a simple implementation for query class.[BR] Prehaps someone might find this patch useful, at least while it's not implemented in trunk.

  2. Former user Account Deleted

    Wow, three years and “awaiting triage”...

    To underline the severity here, I show how a decent group_by is affected:

    SELECT a, b, c FROM x GROUP BY a

    gets an error with PostgreSQL, because it doesn’t like to have b and c outside of aggregate functions. A DISTINCT ON a should be used in stead, which gives us any random b and c that fits -- that’s what I want.

  3. Mike Bayer reporter
    • changed milestone to 0.7.0

    Replying to guest:

    Wow, three years and “awaiting triage”...

    To underline the severity here, I show how a decent group_by is affected:

    SELECT a, b, c FROM x GROUP BY a

    gets an error with PostgreSQL, because it doesn’t like to have b and c outside of aggregate functions. A DISTINCT ON a should be used in stead, which gives us any random b and c that fits -- that’s what I want.

    GROUP BY is mostly to do with grouping so that aggregates can be applied. The above query can link the selection of 'b' and 'c' to that of 'a' via a subquery, which is probably why I never find myself needing "DISTINCT ON".

  4. Log in to comment