From 8acbc2624fb4b457e47fab93e6a44a1e37caeddc Mon Sep 17 00:00:00 2001 From: raylu Date: Wed, 20 Mar 2019 17:22:19 -0400 Subject: Expand joins when calculating PostgreSQL "WITH FOR UPDATE OF" Modified the :paramref:`.Select.with_for_update.of` parameter so that if a join or other composed selectable is passed, the individual :class:`.Table` objects will be filtered from it, allowing one to pass a join() object to the parameter, as occurs normally when using joined table inheritance with the ORM. Pull request courtesy Raymond Lu. Fixes: #4550 Co-authored-by: Mike Bayer Closes: #4551 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4551 Pull-request-sha: 452da77d154a4087d530456db1c9af207d65cef4 Change-Id: If4b7c231f7b71190d7245543959fb5c3351125a1 --- lib/sqlalchemy/dialects/postgresql/base.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/base.py') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 4d302dabe..3781a7ba2 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -929,6 +929,7 @@ from ...sql import compiler from ...sql import elements from ...sql import expression from ...sql import sqltypes +from ...sql import util as sql_util from ...types import BIGINT from ...types import BOOLEAN from ...types import CHAR @@ -1681,10 +1682,11 @@ class PGCompiler(compiler.SQLCompiler): tmp = " FOR UPDATE" if select._for_update_arg.of: - tables = util.OrderedSet( - c.table if isinstance(c, expression.ColumnClause) else c - for c in select._for_update_arg.of - ) + + tables = util.OrderedSet() + for c in select._for_update_arg.of: + tables.update(sql_util.surface_selectables_only(c)) + tmp += " OF " + ", ".join( self.process(table, ashint=True, use_schema=False, **kw) for table in tables -- cgit v1.2.1