@@ -121,27 +121,36 @@ def query_external_table_schema(self, path: DbPath) -> Dict[str, tuple]:
121
121
if not rows :
122
122
raise RuntimeError (f"{ self .name } : Table '{ '.' .join (path )} ' does not exist, or has no columns" )
123
123
124
- d = { r [ 0 ]: r for r in rows }
125
- assert len ( d ) == len ( rows )
126
- return d
124
+ schema_dict = self . _normalize_schema_info ( rows )
125
+
126
+ return schema_dict
127
127
128
128
def select_view_columns (self , path : DbPath ) -> str :
129
129
_ , schema , table = self ._normalize_table_path (path )
130
130
131
131
return """select * from pg_get_cols('{}.{}')
132
- cols(view_schema name, view_name name, col_name name, col_type varchar, col_num int)
133
- """ .format (schema , table )
132
+ cols(col_name name, col_type varchar)
133
+ """ .format (
134
+ schema , table
135
+ )
134
136
135
137
def query_pg_get_cols (self , path : DbPath ) -> Dict [str , tuple ]:
136
138
rows = self .query (self .select_view_columns (path ), list )
137
139
138
140
if not rows :
139
141
raise RuntimeError (f"{ self .name } : View '{ '.' .join (path )} ' does not exist, or has no columns" )
140
142
141
- output = {}
143
+ schema_dict = self ._normalize_schema_info (rows )
144
+
145
+ return schema_dict
146
+
147
+ # when using a non-information_schema source, strip (N) from type(N) etc. to match
148
+ # typical information_schema output
149
+ def _normalize_schema_info (self , rows ) -> Dict [str , tuple ]:
150
+ schema_dict = {}
142
151
for r in rows :
143
- col_name = r [2 ]
144
- type_info = r [3 ].split ("(" )
152
+ col_name = r [0 ]
153
+ type_info = r [1 ].split ("(" )
145
154
base_type = type_info [0 ]
146
155
precision = None
147
156
scale = None
@@ -153,9 +162,8 @@ def query_pg_get_cols(self, path: DbPath) -> Dict[str, tuple]:
153
162
scale = int (scale )
154
163
155
164
out = [col_name , base_type , None , precision , scale ]
156
- output [col_name ] = tuple (out )
157
-
158
- return output
165
+ schema_dict [col_name ] = tuple (out )
166
+ return schema_dict
159
167
160
168
def query_table_schema (self , path : DbPath ) -> Dict [str , tuple ]:
161
169
try :
0 commit comments