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

Commit ce6dd61

Browse files
committed
override normalize_table_path to support 3 part id
1 parent ffc4afe commit ce6dd61

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

sqeleton/databases/redshift.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ class Redshift(PostgreSQL):
6464
CONNECT_URI_PARAMS = ["database?"]
6565

6666
def select_table_schema(self, path: DbPath) -> str:
67-
schema, table = self._normalize_table_path(path)
67+
_, schema, table = self._normalize_table_path(path)
6868

6969
return (
7070
"SELECT column_name, data_type, datetime_precision, numeric_precision, numeric_scale FROM information_schema.columns "
7171
f"WHERE table_name = '{table.lower()}' AND table_schema = '{schema.lower()}'"
7272
)
7373

7474
def select_external_table_schema(self, path: DbPath) -> str:
75-
schema, table = self._normalize_table_path(path)
75+
_, schema, table = self._normalize_table_path(path)
7676

7777
return f"""SELECT
7878
columnname AS column_name
@@ -98,3 +98,15 @@ def query_table_schema(self, path: DbPath) -> Dict[str, tuple]:
9898
return super().query_table_schema(path)
9999
except RuntimeError:
100100
return self.query_external_table_schema(path)
101+
102+
def _normalize_table_path(self, path: DbPath) -> DbPath:
103+
if len(path) == 1:
104+
return None, self.default_schema, path[0]
105+
elif len(path) == 2:
106+
return None, path[0], path[1]
107+
elif len(path) == 3:
108+
return path
109+
110+
raise ValueError(
111+
f"{self.name}: Bad table path for {self}: '{'.'.join(path)}'. Expected format: table, schema.table, or database.schema.table"
112+
)

0 commit comments

Comments
 (0)