Skip to content

Commit e0d78bb

Browse files
authored
Fix: Add an alias to a subquery of ordered projections (#1450)
1 parent fed34b1 commit e0d78bb

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

sqlmesh/core/engine_adapter/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ def _insert_append_query(
760760
query = self._escape_json(query)
761761
if order_projections and query.named_selects != list(columns_to_types):
762762
if isinstance(query, exp.Subqueryable):
763-
query = query.subquery()
763+
query = query.subquery(alias="_ordered_projections")
764764
query = exp.select(*columns_to_types).from_(query)
765765
self.execute(exp.insert(query, table_name, columns=list(columns_to_types)))
766766

tests/core/engine_adapter/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def test_insert_append_query_select_star(make_mocked_engine_adapter: t.Callable)
274274
)
275275

276276
assert to_sql_calls(adapter) == [
277-
'INSERT INTO "test_table" ("a", "b") SELECT "a", "b" FROM (SELECT 1 AS "a", * FROM "tbl")',
277+
'INSERT INTO "test_table" ("a", "b") SELECT "a", "b" FROM (SELECT 1 AS "a", * FROM "tbl") AS "_ordered_projections"',
278278
]
279279

280280

0 commit comments

Comments
 (0)