diff options
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 |