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

Commit 793ab39

Browse files
authored
Merge pull request #26 from datafold/postgres_select_table_unique_columns
postgres override select_table_unique_columns
2 parents 41ac680 + 1c736ad commit 793ab39

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sqeleton/databases/postgresql.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ def select_table_schema(self, path: DbPath) -> str:
136136
f"WHERE table_name = '{table}' AND table_schema = '{schema}'"
137137
)
138138

139+
def select_table_unique_columns(self, path: DbPath) -> str:
140+
database, schema, table = self._normalize_table_path(path)
141+
142+
info_schema_path = ["information_schema", "key_column_usage"]
143+
if database:
144+
info_schema_path.insert(0, database)
145+
146+
return (
147+
"SELECT column_name "
148+
f"FROM {'.'.join(info_schema_path)} "
149+
f"WHERE table_name = '{table}' AND table_schema = '{schema}'"
150+
)
151+
139152
def _normalize_table_path(self, path: DbPath) -> DbPath:
140153
if len(path) == 1:
141154
return None, self.default_schema, path[0]

0 commit comments

Comments
 (0)