summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-09-19 09:40:40 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-09-19 21:50:03 -0400
commitbbd90a987eea70c28dd1e2ee7007722b16ec9f74 (patch)
tree24bf7bf95ebcbfffa19a0f79814e1cb8526f6192 /lib/sqlalchemy/sql/compiler.py
parent4428dce5a633fca699b423dcb76672a5f9e4c0d8 (diff)
downloadsqlalchemy-bbd90a987eea70c28dd1e2ee7007722b16ec9f74.tar.gz
break out text() from TextualSelect for col matching
Fixed issue where mixing "*" with additional explicitly-named column expressions within the columns clause of a :func:`_sql.select` construct would cause result-column targeting to sometimes consider the label name or other non-repeated names to be an ambiguous target. Fixes: #8536 Change-Id: I3c845eaf571033e54c9208762344f67f4351ac3a (cherry picked from commit 78327d98be9236c61f950526470f29b184dabba6)
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index c9b6ba670..0e441fbec 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -611,6 +611,20 @@ class SQLCompiler(Compiled):
_textual_ordered_columns = False
"""tell the result object that the column names as rendered are important,
but they are also "ordered" vs. what is in the compiled object here.
+
+ As of 1.4.42 this condition is only present when the statement is a
+ TextualSelect, e.g. text("....").columns(...), where it is required
+ that the columns are considered positionally and not by name.
+
+ """
+
+ _ad_hoc_textual = False
+ """tell the result that we encountered text() or '*' constructs in the
+ middle of the result columns, but we also have compiled columns, so
+ if the number of columns in cursor.description does not match how many
+ expressions we have, that means we can't rely on positional at all and
+ should match on name.
+
"""
_ordered_columns = True
@@ -3024,7 +3038,7 @@ class SQLCompiler(Compiled):
def _add_to_result_map(self, keyname, name, objects, type_):
if keyname is None or keyname == "*":
self._ordered_columns = False
- self._textual_ordered_columns = True
+ self._ad_hoc_textual = True
if type_._is_tuple_type:
raise exc.CompileError(
"Most backends don't support SELECTing "