Skip to content

Commit e8c8cef

Browse files
authored
fix: fix scd type 2 replace query mixin (#1491)
1 parent f7a8e01 commit e8c8cef

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

sqlmesh/core/engine_adapter/mixins.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,19 @@ def replace_query(
9090
with source_queries[0] as query:
9191
target_table = exp.to_table(table_name)
9292
# Check if self-referencing
93-
if any(
93+
matching_tables = [
9494
table
9595
for table in query.find_all(exp.Table)
9696
if quote_identifiers(table) == quote_identifiers(target_table)
97-
):
97+
]
98+
if matching_tables:
9899
with self.temp_table(
99100
exp.select(*columns_to_types).from_(target_table),
100101
target_table,
101102
columns_to_types,
102103
) as temp_table:
103-
for table in query.find_all(exp.Table):
104-
if table == target_table:
105-
table.replace(temp_table.copy())
104+
for table in matching_tables:
105+
table.replace(temp_table.copy())
106106
self.execute(self._truncate_table(table_name))
107107
return self._insert_append_query(table_name, query, columns_to_types)
108108
self.execute(self._truncate_table(table_name))

0 commit comments

Comments
 (0)