diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-06-13 15:59:35 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-06-13 21:38:20 -0400 |
commit | 58540ae93db30fb12f331587c32bb2d76db79ab3 (patch) | |
tree | 8a54bd2584b6a11ac705040e24e31f64c40aa366 /lib/sqlalchemy/sql/compiler.py | |
parent | da5323c2fae39aab45d305f723a73483563b2307 (diff) | |
download | sqlalchemy-58540ae93db30fb12f331587c32bb2d76db79ab3.tar.gz |
Support JOIN in UPDATE..FROM
The :class:`.Update` construct now accommodates a :class:`.Join` object
as supported by MySQL for UPDATE..FROM. As the construct already
accepted an alias object for a similar purpose, the feature of UPDATE
against a non-table was already implied so this has been added.
Change-Id: I7b2bca627849384d5377abb0c94626463e4fad04
Fixes: #3645
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index a442c65fd..f6cdebb16 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2178,6 +2178,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 " @@ -2186,8 +2196,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) @@ -2200,7 +2209,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, @@ -2217,7 +2226,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 |