DISTINCT ON ignored for Union

Bug #799824 reported by Gavin Panella
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Storm
New
Undecided
Unassigned

Bug Description

A DISTINCT clause does not appear in the query that is executed by the
following (contrived) query:

  union = store.find(Distribution).union(
      store.find(Distribution), all=True)
  union.config(distinct=(Distribution.name,))
  list(union)

A DISTINCT clause does not appear if config(distinct=True) is used
either, although a straight UNION (i.e. without ALL) has the same
effect I think. However the newish DISTINCT ON syntax in PostgreSQL
has different properties.

The query should look something like:

  SELECT DISTINCT ON (_1.name) * FROM (
    (SELECT ... FROM Distribution)
  UNION ALL
    (SELECT ... FROM Distribution)
  ) AS "_1" ORDER BY name

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

In postgres at least, a regular UNION implies a full DISTINCT (which the ALL option then removes). It removes duplicate rows within one member of the union as well as duplicates across the member queries.

So from Storm's perspective, this looks like an omission in the implementation of "DISTINCT ON" support. It might make more sense to deprecate the "all" parameter to the union method, and use distinct=False instead. The only wart on that is that a union would have a different default than a regular select.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.