]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Add a third labeling mode for SELECT statements
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Mar 2020 18:24:39 +0000 (14:24 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 30 Mar 2020 02:27:41 +0000 (22:27 -0400)
commita65d5c250e9fd7090311ef12f28d7d959c6c738e
tree349f0b4c1127c3d87d9cffb62b5d6e02979a3a9a
parent8e857e3f6beecf7510f741428d8d0ba24f5cb71b
Add a third labeling mode for SELECT statements

Enhanced the disambiguating labels feature of the
:func:`~.sql.expression.select` construct such that when a select statement
is used in a subquery, repeated column names from different tables are now
automatically labeled with a unique label name, without the need to use the
full "apply_labels()" feature that conbines tablename plus column name.
The disambigated labels are available as plain string keys in the .c
collection of the subquery, and most importantly the feature allows an ORM
:func:`.orm.aliased` construct against the combination of an entity and an
arbitrary subquery to work correctly, targeting the correct columns despite
same-named columns in the source tables, without the need for an "apply
labels" warning.

The existing labeling style is now called
LABEL_STYLE_TABLENAME_PLUS_COL.  This labeling style will remain used
throughout the ORM as has been the case for over a decade, however,
the new disambiguation scheme could theoretically replace this scheme
entirely.  The new scheme would dramatically alter how SQL looks
when rendered from the ORM to be more succinct but arguably harder
to read.

The tablename_columnname scheme used by Join.c is unaffected here,
as that's still hardcoded to that scheme.

Fixes: #5221
Change-Id: Ib47d9e0f35046b3afc77bef6e65709b93d0c3026
13 files changed:
doc/build/changelog/migration_20.rst
doc/build/changelog/unreleased_14/5221.rst [new file with mode: 0644]
lib/sqlalchemy/ext/baked.py
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/sql/base.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/elements.py
lib/sqlalchemy/sql/selectable.py
lib/sqlalchemy/testing/assertions.py
lib/sqlalchemy/util/deprecations.py
test/orm/test_query.py
test/sql/test_compare.py
test/sql/test_selectable.py