]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Label simple column transformations as the column name
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 27 Aug 2019 21:08:11 +0000 (17:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 28 Aug 2019 21:11:15 +0000 (17:11 -0400)
commit3bb402ff8ed980ae393def7462b1da49c0e0a8a7
treeac4a0a3cfef40d785fecd79015f75caf51054070
parent5bf264ca08b8bb38d50baeb48fe1729da4164711
Label simple column transformations as the column name

Additional logic has been added such that certain SQL expressions which
typically wrap a single database column will use the name of that column as
their "anonymous label" name within a SELECT statement, potentially making
key-based lookups in result tuples more intutive.   The primary example of
this is that of a CAST expression, e.g. ``CAST(table.colname AS INTEGER)``,
which will export its default name as "colname", rather than the usual
"anon_1" label, that is, ``CAST(table.colname AS INTEGER) AS colname``.
If the inner expression doesn't have a name, then the previous "anonymous
label" logic is used.  When using SELECT statements that make use of
:meth:`.Select.apply_labels`, such as those emitted by the ORM, the
labeling logic will produce ``<tablename>_<inner column name>`` in the same
was as if the column were named alone.   The logic applies right now to the
:func:`.cast` and :func:`.type_coerce` constructs as well as some
single-element boolean expressions.

Fixes: #4449
Change-Id: Ie3b73470e3bea53f2386cd86514cdc556491564e
doc/build/changelog/migration_14.rst
doc/build/changelog/unreleased_14/4449.rst [new file with mode: 0644]
doc/build/core/sqlelement.rst
doc/build/core/tutorial.rst
lib/sqlalchemy/sql/elements.py
test/dialect/mssql/test_compiler.py
test/sql/test_compiler.py
test/sql/test_labels.py
test/sql/test_type_expressions.py
test/sql/test_types.py