@@ -122,6 +122,38 @@ def query_pg_get_cols(self, path: DbPath) -> Dict[str, tuple]:
122122
123123 return schema_dict
124124
125+ def select_svv_columns_schema (self , path : DbPath ) -> Dict [str , tuple ]:
126+ database , schema , table = self ._normalize_table_path (path )
127+
128+ db_clause = ""
129+ if database :
130+ db_clause = f" AND table_catalog = '{ database .lower ()} '"
131+
132+ return (
133+ f"""
134+ select
135+ distinct
136+ column_name,
137+ data_type,
138+ datetime_precision,
139+ numeric_precision,
140+ numeric_scale
141+ from
142+ svv_columns
143+ where table_name = '{ table .lower ()} ' and table_schema = '{ schema .lower ()} '
144+ """
145+ + db_clause
146+ )
147+
148+ def query_svv_columns (self , path : DbPath ) -> Dict [str , tuple ]:
149+ rows = self .query (self .select_svv_columns_schema (path ), list )
150+ if not rows :
151+ raise RuntimeError (f"{ self .name } : Table '{ '.' .join (path )} ' does not exist, or has no columns" )
152+
153+ d = {r [0 ]: r for r in rows }
154+ assert len (d ) == len (rows )
155+ return d
156+
125157 # when using a non-information_schema source, strip (N) from type(N) etc. to match
126158 # typical information_schema output
127159 def _normalize_schema_info (self , rows ) -> Dict [str , tuple ]:
@@ -150,7 +182,10 @@ def query_table_schema(self, path: DbPath) -> Dict[str, tuple]:
150182 try :
151183 return self .query_external_table_schema (path )
152184 except RuntimeError :
153- return self .query_pg_get_cols (path )
185+ try :
186+ return self .query_pg_get_cols (path )
187+ except Exception :
188+ return self .query_svv_columns (path )
154189
155190 def _normalize_table_path (self , path : DbPath ) -> DbPath :
156191 if len (path ) == 1 :
0 commit comments