diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-02-09 17:49:38 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-02-09 17:49:38 -0500 |
| commit | ff3be95620b6505943b2d7e4688abc29dca3e493 (patch) | |
| tree | 1d90206b004c30bc296d709d5d169bf8a1f2a16a /doc | |
| parent | 7d2bed69abb6ab545cfa5ca967141338387417c2 (diff) | |
| download | sqlalchemy-ff3be95620b6505943b2d7e4688abc29dca3e493.tar.gz | |
- A refinement to the logic which adds columns to the resulting SQL when
:meth:`.Query.distinct` is combined with :meth:`.Query.order_by` such
that columns which are already present will not be added
a second time, even if they are labeled with a different name.
Regardless of this change, the extra columns added to the SQL have
never been returned in the final result, so this change only impacts
the string form of the statement as well as its behavior when used in
a Core execution context. Additionally, columns are no longer added
when the DISTINCT ON format is used, provided the query is not
wrapped inside a subquery due to joined eager loading.
fixes #3641
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/build/changelog/changelog_11.rst | 19 | ||||
| -rw-r--r-- | doc/build/changelog/migration_11.rst | 41 |
2 files changed, 59 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 5c3ad7163..2473a02a2 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -22,6 +22,25 @@ :version: 1.1.0b1 .. change:: + :tags: bug, orm + :tickets: 3641 + + A refinement to the logic which adds columns to the resulting SQL when + :meth:`.Query.distinct` is combined with :meth:`.Query.order_by` such + that columns which are already present will not be added + a second time, even if they are labeled with a different name. + Regardless of this change, the extra columns added to the SQL have + never been returned in the final result, so this change only impacts + the string form of the statement as well as its behavior when used in + a Core execution context. Additionally, columns are no longer added + when the DISTINCT ON format is used, provided the query is not + wrapped inside a subquery due to joined eager loading. + + .. seealso:: + + :ref:`change_3641` + + .. change:: :tags: feature, sql :tickets: 3292, 3095 diff --git a/doc/build/changelog/migration_11.rst b/doc/build/changelog/migration_11.rst index 07223be34..3d65ede80 100644 --- a/doc/build/changelog/migration_11.rst +++ b/doc/build/changelog/migration_11.rst @@ -16,7 +16,7 @@ What's New in SQLAlchemy 1.1? some issues may be moved to later milestones in order to allow for a timely release. - Document last updated: January 29, 2016 + Document last updated: Feburary 9, 2016 Introduction ============ @@ -487,6 +487,45 @@ associated with any bound :class:`.Engine`, then the fallback to the :ticket:`3081` +.. _change_3641: + +Columns no longer added redundantly with DISTINCT + ORDER BY +------------------------------------------------------------ + +A query such as the following will now augment only those columns +that are missing from the SELECT list, without duplicates:: + + q = session.query(User.id, User.name.label('name')).\ + distinct().\ + order_by(User.id, User.name, User.fullname) + +Produces:: + + SELECT DISTINCT user.id AS a_id, user.name AS name, + user.fullname AS a_fullname + FROM a ORDER BY user.id, user.name, user.fullname + +Previously, it would produce:: + + SELECT DISTINCT user.id AS a_id, user.name AS name, user.name AS a_name, + user.fullname AS a_fullname + FROM a ORDER BY user.id, user.name, user.fullname + +Where above, the ``user.name`` column is added unnecessarily. The results +would not be affected, as the additional columns are not included in the +result in any case, but the columns are unnecessary. + +Additionally, when the Postgresql DISTINCT ON format is used by passing +expressions to :meth:`.Query.distinct`, the above "column adding" logic +is disabled entirely. + +When the query is being bundled into a subquery for the purposes of +joined eager loading, the "augment column list" rules are are necessarily +more aggressive so that the ORDER BY can still be satisifed, so this case +remains unchanged. + +:ticket:`3641` + New Features and Improvements - Core ==================================== |
