summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2018-06-25 18:38:11 -0400
committerGerrit Code Review <gerrit@ci.zzzcomputing.com>2018-06-25 18:38:11 -0400
commit677818707471db670d5c3a83b10ebbc65f871881 (patch)
treea33703267eec24e2ce7d837f4885eb2258b0cdd0 /lib/sqlalchemy/sql/compiler.py
parentc99345ee9994c3ea2a5e6536cc3365f18d017cc1 (diff)
parent58540ae93db30fb12f331587c32bb2d76db79ab3 (diff)
downloadsqlalchemy-677818707471db670d5c3a83b10ebbc65f871881.tar.gz
Merge "Support JOIN in UPDATE..FROM"
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 0b98dc51c..75827b34e 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -2183,6 +2183,16 @@ class SQLCompiler(Compiled):
"selectable": update_stmt})
extra_froms = update_stmt._extra_froms
+ is_multitable = bool(extra_froms)
+
+ if is_multitable:
+ # main table might be a JOIN
+ main_froms = set(selectable._from_objects(update_stmt.table))
+ render_extra_froms = [
+ f for f in extra_froms if f not in main_froms
+ ]
+ else:
+ render_extra_froms = []
text = "UPDATE "
@@ -2191,8 +2201,7 @@ class SQLCompiler(Compiled):
update_stmt._prefixes, **kw)
table_text = self.update_tables_clause(update_stmt, update_stmt.table,
- extra_froms, **kw)
-
+ render_extra_froms, **kw)
crud_params = crud._setup_crud_params(
self, update_stmt, crud.ISUPDATE, **kw)
@@ -2205,7 +2214,7 @@ class SQLCompiler(Compiled):
text += table_text
text += ' SET '
- include_table = extra_froms and \
+ include_table = is_multitable and \
self.render_table_with_column_in_update_from
text += ', '.join(
c[0]._compiler_dispatch(self,
@@ -2222,7 +2231,7 @@ class SQLCompiler(Compiled):
extra_from_text = self.update_from_clause(
update_stmt,
update_stmt.table,
- extra_froms,
+ render_extra_froms,
dialect_hints, **kw)
if extra_from_text:
text += " " + extra_from_text