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

Commit b3e1d8a

Browse files
committed
Fix for Redshift
1 parent 0232343 commit b3e1d8a

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

data_diff/database.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ class Database(AbstractDatabase):
209209
Instanciated using :meth:`~data_diff.connect_to_uri`
210210
"""
211211

212-
DATETIME_TYPES = NotImplemented
213-
default_schema = NotImplemented
212+
DATETIME_TYPES = {}
213+
default_schema = None
214214

215215
def query(self, sql_ast: SqlOrStr, res_type: type):
216216
"Query the given SQL code/AST, and attempt to convert the result to type 'res_type'"
@@ -306,13 +306,15 @@ def query_table_schema(self, path: DbPath) -> Dict[str, ColType]:
306306

307307
def _normalize_table_path(self, path: DbPath) -> DbPath:
308308
if len(path) == 1:
309-
return self.default_schema, path[0]
310-
elif len(path) == 2:
311-
return path
309+
if self.default_schema:
310+
return self.default_schema, path[0]
311+
elif len(path) != 2:
312+
raise ValueError(
313+
f"{self.__class__.__name__}: Bad table path for {self}: '{'.'.join(path)}'. Expected form: schema.table"
314+
)
315+
316+
return path
312317

313-
raise ValueError(
314-
f"{self.__class__.__name__}: Bad table path for {self}: '{'.'.join(path)}'. Expected form: schema.table"
315-
)
316318

317319
def parse_table_name(self, name: str) -> DbPath:
318320
return parse_table_name(name)
@@ -713,6 +715,14 @@ def normalize_value_by_type(self, value: str, coltype: ColType) -> str:
713715

714716
return self.to_string(f"{value}")
715717

718+
def select_table_schema(self, path: DbPath) -> str:
719+
schema, table = self._normalize_table_path(path)
720+
721+
return (
722+
"SELECT column_name, data_type, datetime_precision, numeric_precision, numeric_scale FROM information_schema.columns "
723+
f"WHERE table_name = '{table.lower()}' AND table_schema = '{schema.lower()}'"
724+
)
725+
716726

717727
class MsSQL(ThreadedDatabase):
718728
"AKA sql-server"

0 commit comments

Comments
 (0)