diff --git a/src/snowflake/sqlalchemy/base.py b/src/snowflake/sqlalchemy/base.py index e9125315..0211e713 100644 --- a/src/snowflake/sqlalchemy/base.py +++ b/src/snowflake/sqlalchemy/base.py @@ -158,8 +158,11 @@ def visit_merge_into(self, merge_into, **kw): clauses = " ".join( clause._compiler_dispatch(self, **kw) for clause in merge_into.clauses ) + target = merge_into.target._compiler_dispatch(self, asfrom=True, **kw) + source = merge_into.source._compiler_dispatch(self, asfrom=True, **kw) + on = merge_into.on._compiler_dispatch(self, **kw) return ( - f"MERGE INTO {merge_into.target} USING {merge_into.source} ON {merge_into.on}" + f"MERGE INTO {target} USING {source} ON {on}" + (" " + clauses if clauses else "") ) @@ -207,11 +210,7 @@ def visit_copy_into(self, copy_into, **kw): formatter = copy_into.formatter._compiler_dispatch(self, **kw) else: formatter = "" - into = ( - copy_into.into - if isinstance(copy_into.into, Table) - else copy_into.into._compiler_dispatch(self, **kw) - ) + into = copy_into.into._compiler_dispatch(self, asfrom=True, **kw) from_ = None if isinstance(copy_into.from_, Table): from_ = copy_into.from_