summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-11-07 18:40:03 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-11-11 14:48:49 -0500
commitf44e233dccd7739a9f73a2ea16ce6b5b8d7d0f5f (patch)
tree170febc81dd799e96f7c304c887224c84d6c6daa /lib/sqlalchemy/sql/compiler.py
parent1175768618d3a84578b90befe73240b417ebeb78 (diff)
downloadsqlalchemy-f44e233dccd7739a9f73a2ea16ce6b5b8d7d0f5f.tar.gz
establish consistency for RETURNING column labels
For the PostgreSQL and SQL Server dialects only, adjusted the compiler so that when rendering column expressions in the RETURNING clause, the "non anon" label that's used in SELECT statements is suggested for SQL expression elements that generate a label; the primary example is a SQL function that may be emitting as part of the column's type, where the label name should match the column's name by default. This restores a not-well defined behavior that had changed in version 1.4.21 due to :ticket:`6718`, :ticket:`6710`. The Oracle dialect has a different RETURNING implementation and was not affected by this issue. Version 2.0 features an across the board change for its widely expanded support of RETURNING on other backends. Fixed issue in the Oracle dialect where an INSERT statement that used ``insert(some_table).values(...).returning(some_table)`` against a full :class:`.Table` object at once would fail to execute, raising an exception. Fixes: #8770 Change-Id: I2ab078a214a778ffe1720dbd864ae4c105a0691d (cherry picked from commit c8a7b67181d31634355150fc0379ec0e780ff728)
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 0e441fbec..a7232f096 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -3047,7 +3047,9 @@ class SQLCompiler(Compiled):
)
self._result_columns.append((keyname, name, objects, type_))
- def _label_returning_column(self, stmt, column, column_clause_args=None):
+ def _label_returning_column(
+ self, stmt, column, column_clause_args=None, **kw
+ ):
"""Render a column with necessary labels inside of a RETURNING clause.
This method is provided for individual dialects in place of calling
@@ -3063,6 +3065,7 @@ class SQLCompiler(Compiled):
True,
False,
{} if column_clause_args is None else column_clause_args,
+ **kw
)
def _label_select_column(
@@ -3127,7 +3130,6 @@ class SQLCompiler(Compiled):
"_label_select_column is only relevant within "
"the columns clause of a SELECT or RETURNING"
)
-
if isinstance(column, elements.Label):
if col_expr is not column:
result_expr = _CompileLabel(
@@ -4319,7 +4321,9 @@ class StrSQLCompiler(SQLCompiler):
def returning_clause(self, stmt, returning_cols):
columns = [
- self._label_select_column(None, c, True, False, {})
+ self._label_select_column(
+ None, c, True, False, {}, fallback_label_name=c._non_anon_label
+ )
for c in base._select_iterables(returning_cols)
]