Skip to content

Commit 48eaba3

Browse files
authored
Fix: Support columns for late-binding views in Redshift. (#906)
1 parent 69e810b commit 48eaba3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sqlmesh/core/engine_adapter/redshift.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ def create_view(
5454
view_name, query_or_df, columns_to_types, replace, no_schema_binding=True
5555
)
5656

57+
def columns(self, table_name: TableName) -> t.Dict[str, exp.DataType]:
58+
"""Fetches column names and types for the target table."""
59+
# Use Redshift's SVV_COLUMNS table, which includes columns for late-binding views.
60+
table = exp.to_table(table_name)
61+
sql = (
62+
exp.select("column_name", "data_type")
63+
.from_("SVV_COLUMNS")
64+
.where(f"table_name = '{table.alias_or_name}' AND table_schema = '{table.db}'")
65+
)
66+
self.execute(sql)
67+
resp = self.cursor.fetchall()
68+
return {column: exp.DataType.build(type, dialect=self.dialect) for column, type in resp}
69+
5770
def _fetch_native_df(self, query: t.Union[exp.Expression, str]) -> pd.DataFrame:
5871
"""Fetches a Pandas DataFrame from the cursor"""
5972
self.execute(query)

0 commit comments

Comments
 (0)