Skip to content

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

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Michael Bayer (@zzzeek)

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.


Attachments: ticket_1069.patch

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Jun 2, 2008

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed title from "implement "DISTINCT ON" for PG; remove old "distin" to "add array arg to select().distinct() query().disti"
sqlalchemy-bot

sqlalchemy-bot commented on Jul 14, 2008

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed milestone from "0.5.0" to "0.5.xx"
sqlalchemy-bot

sqlalchemy-bot commented on Aug 18, 2009

@sqlalchemy-bot
CollaboratorAuthor

Anonymous wrote:

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.

sqlalchemy-bot

sqlalchemy-bot commented on Feb 9, 2011

@sqlalchemy-bot
CollaboratorAuthor

Anonymous wrote:

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.

sqlalchemy-bot

sqlalchemy-bot commented on Feb 9, 2011

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

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".

sqlalchemy-bot

sqlalchemy-bot commented on Feb 9, 2011

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed milestone from "0.6.xx" to "0.7.0"
sqlalchemy-bot

sqlalchemy-bot commented on Feb 9, 2011

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

note a more complete patch has been attached but still needs tests.

sqlalchemy-bot

sqlalchemy-bot commented on Feb 10, 2011

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

3f9a343

sqlalchemy-bot

sqlalchemy-bot commented on Feb 10, 2011

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
added this to the 0.7.0 milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          add array arg to select().distinct(), query().distinct() · Issue #1069 · sqlalchemy/sqlalchemy