Skip to content

Commit d75cb4b

Browse files
authored
Use the same select_table_schema and _normalize_table_path as Redshift (#2)
1 parent 53f804a commit d75cb4b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

sqeleton/databases/duckdb.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,26 @@ def create_connection(self):
167167
except ddb.OperationalError as e:
168168
raise ConnectError(*e.args) from e
169169

170+
def select_table_schema(self, path: DbPath) -> str:
171+
database, schema, table = self._normalize_table_path(path)
172+
173+
info_schema_path = ["information_schema", "columns"]
174+
if database:
175+
info_schema_path.insert(0, database)
176+
177+
return (
178+
f"SELECT column_name, data_type, datetime_precision, numeric_precision, numeric_scale FROM {'.'.join(info_schema_path)} "
179+
f"WHERE table_name = '{table.lower()}' AND table_schema = '{schema.lower()}'"
180+
)
181+
170182
def _normalize_table_path(self, path: DbPath) -> DbPath:
171183
if len(path) == 1:
172-
return self.default_schema, path[0]
184+
return None, self.default_schema, path[0]
173185
elif len(path) == 2:
186+
return None, path[0], path[1]
187+
elif len(path) == 3:
174188
return path
175-
elif len(path) > 2:
176-
# Use only the last two values from the path
177-
return path[-2:]
178189

179-
raise ValueError(f"{self.name}: Bad table path for {self}: '{'.'.join(path)}'. Expected form: schema.table")
190+
raise ValueError(
191+
f"{self.name}: Bad table path for {self}: '{'.'.join(path)}'. Expected format: table, schema.table, or database.schema.table"
192+
)

0 commit comments

Comments
 (0)