From aceefb508ccd0911f52ff0e50324b3fefeaa3f16 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 7 Jul 2019 11:12:31 -0400 Subject: Allow duplicate columns in from clauses and selectables The :func:`.select` construct and related constructs now allow for duplication of column labels and columns themselves in the columns clause, mirroring exactly how column expressions were passed in. This allows the tuples returned by an executed result to match what was SELECTed for in the first place, which is how the ORM :class:`.Query` works, so this establishes better cross-compatibility between the two constructs. Additionally, it allows column-positioning-sensitive structures such as UNIONs (i.e. :class:`.CompoundSelect`) to be more intuitively constructed in those cases where a particular column might appear in more than one place. To support this change, the :class:`.ColumnCollection` has been revised to support duplicate columns as well as to allow integer index access. Fixes: #4753 Change-Id: Ie09a8116f05c367995c1e43623c51e07971d3bf0 --- lib/sqlalchemy/sql/functions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql/functions.py') diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index 04fb16a80..2feb6fd5f 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -118,7 +118,8 @@ class FunctionElement(Executable, ColumnElement, FromClause): """ - return ColumnCollection(self.label(None)) + col = self.label(None) + return ColumnCollection(columns=[(col.key, col)]) @util.memoized_property def clauses(self): -- cgit v1.2.1