From 885c61cf226695cafa12e56ed047ba761c2f7f93 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 7 Sep 2022 17:13:23 -0400 Subject: enable UPDATE..FROM for SQLite The SQLite dialect now supports UPDATE..FROM syntax, for UPDATE statements that may refer to additional tables within the WHERE criteria of the statement without the need to use subqueries. This syntax is invoked automatically when using the :class:`_dml.Update` construct when more than one table or other entity or selectable is used. Fixes: #7185 Change-Id: I27e94ace9ff761cc45e652fa1abff8cd1f42fec5 --- lib/sqlalchemy/dialects/sqlite/base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/sqlalchemy/dialects/sqlite') diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 222f3a137..88c6dbe18 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -1381,6 +1381,15 @@ class SQLiteCompiler(compiler.SQLCompiler): # sqlite has no "FOR UPDATE" AFAICT return "" + def update_from_clause( + self, update_stmt, from_table, extra_froms, from_hints, **kw + ): + kw["asfrom"] = True + return "FROM " + ", ".join( + t._compiler_dispatch(self, fromhints=from_hints, **kw) + for t in extra_froms + ) + def visit_is_distinct_from_binary(self, binary, operator, **kw): return "%s IS NOT %s" % ( self.process(binary.left), @@ -1933,6 +1942,7 @@ class SQLiteDialect(default.DefaultDialect): insert_returning = True update_returning = True delete_returning = True + update_returning_multifrom = True default_paramstyle = "qmark" execution_ctx_cls = SQLiteExecutionContext -- cgit v1.2.1