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

Commit 6c43fcf

Browse files
committed
use db values
1 parent ce6dd61 commit 6c43fcf

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sqeleton/databases/redshift.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,23 @@ 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+
database, schema, table = self._normalize_table_path(path)
68+
69+
info_schema_path = ["information_schema", "columns"]
70+
if database:
71+
info_schema_path.insert(0, database)
6872

6973
return (
70-
"SELECT column_name, data_type, datetime_precision, numeric_precision, numeric_scale FROM information_schema.columns "
74+
f"SELECT column_name, data_type, datetime_precision, numeric_precision, numeric_scale FROM {'.'.join(info_schema_path)} "
7175
f"WHERE table_name = '{table.lower()}' AND table_schema = '{schema.lower()}'"
7276
)
7377

7478
def select_external_table_schema(self, path: DbPath) -> str:
75-
_, schema, table = self._normalize_table_path(path)
79+
database, schema, table = self._normalize_table_path(path)
80+
81+
db_clause = ""
82+
if database:
83+
db_clause = f" AND redshift_database_name = '{database.lower()}'"
7684

7785
return f"""SELECT
7886
columnname AS column_name
@@ -82,7 +90,7 @@ def select_external_table_schema(self, path: DbPath) -> str:
8290
, NULL AS numeric_scale
8391
FROM svv_external_columns
8492
WHERE tablename = '{table.lower()}' AND schemaname = '{schema.lower()}'
85-
"""
93+
""" + db_clause
8694

8795
def query_external_table_schema(self, path: DbPath) -> Dict[str, tuple]:
8896
rows = self.query(self.select_external_table_schema(path), list)

0 commit comments

Comments
 (0)