Skip to content

Commit bb10366

Browse files
authored
Fix: Support syntethic projections added to the plan by redshift (#2225)
1 parent 3f1a637 commit bb10366

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

sqlmesh/core/engine_adapter/redshift.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
SourceQuery,
2121
set_catalog,
2222
)
23+
from sqlmesh.utils.errors import SQLMeshError
2324

2425
if t.TYPE_CHECKING:
2526
from sqlmesh.core._typing import SchemaName, TableName
@@ -136,6 +137,17 @@ def _build_create_table_exp(
136137
for target in plan["targetlist"]: # type: ignore
137138
if target["name"] == "TARGETENTRY":
138139
resdom = target["resdom"]
140+
resname = resdom["resname"]
141+
if resname == "<>":
142+
# A synthetic column added by Redshift to compute a window function.
143+
continue
144+
if resname == "? column ?":
145+
table_name_str = (
146+
table_name_or_schema
147+
if isinstance(table_name_or_schema, str)
148+
else table_name_or_schema.sql(dialect=self.dialect)
149+
)
150+
raise SQLMeshError(f"Missing column name for table '{table_name_str}'")
139151
# https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat
140152
if resdom["restype"] == "1043":
141153
size = (
@@ -150,11 +162,11 @@ def _build_create_table_exp(
150162
exp.null(),
151163
f"VARCHAR({size})",
152164
dialect=self.dialect,
153-
).as_(resdom["resname"]),
165+
).as_(resname),
154166
copy=False,
155167
)
156168
else:
157-
select.select(resdom["resname"], copy=False)
169+
select.select(resname, copy=False)
158170

159171
return statement
160172

0 commit comments

Comments
 (0)