Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit cfaf435

Browse files
committed
redshift: also try to get schema from svv_columns
1 parent 6738ca7 commit cfaf435

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

data_diff/databases/redshift.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,29 @@ def query_pg_get_cols(self, path: DbPath) -> Dict[str, tuple]:
122122

123123
return schema_dict
124124

125+
def select_svv_columns_schema(self, path: DbPath) -> Dict[str, tuple]:
126+
database, schema, table = self._normalize_table_path(path)
127+
128+
db_clause = ""
129+
if database:
130+
db_clause = f" AND table_catalog = '{database.lower()}'"
131+
132+
return (
133+
f"""
134+
select
135+
distinct
136+
column_name,
137+
data_type,
138+
datetime_precision,
139+
numeric_precision,
140+
numeric_scale
141+
from
142+
svv_columns
143+
where table_name = '{table.lower()}' and table_schema = '{schema.lower()}'
144+
"""
145+
+ db_clause
146+
)
147+
125148
# when using a non-information_schema source, strip (N) from type(N) etc. to match
126149
# typical information_schema output
127150
def _normalize_schema_info(self, rows) -> Dict[str, tuple]:
@@ -150,7 +173,10 @@ def query_table_schema(self, path: DbPath) -> Dict[str, tuple]:
150173
try:
151174
return self.query_external_table_schema(path)
152175
except RuntimeError:
153-
return self.query_pg_get_cols(path)
176+
try:
177+
return self.query_pg_get_cols(path)
178+
except RuntimeError:
179+
return self.select_svv_columns_schema(path)
154180

155181
def _normalize_table_path(self, path: DbPath) -> DbPath:
156182
if len(path) == 1:

0 commit comments

Comments
 (0)