Commit 7cdc3fe 1 parent b82bafb commit 7cdc3fe Copy full SHA for 7cdc3fe
File tree 1 file changed +16
-3
lines changed
1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -230,18 +230,31 @@ def discover_catalog(mssql_conn, config):
230
230
table_info [db ][table ] = {"row_count" : None , "is_view" : table_type == "VIEW" }
231
231
LOGGER .info ("Tables fetched, fetching columns" )
232
232
cur .execute (
233
- """with constraint_columns as (
233
+ """ with table_constraints as (
234
+ select tc.TABLE_SCHEMA,
235
+ tc.TABLE_NAME,
236
+ tc.CONSTRAINT_NAME,
237
+ tc.CONSTRAINT_TYPE,
238
+ row_number() over (partition by tc.TABLE_SCHEMA, tc.TABLE_NAME
239
+ order by tc.constraint_TYPE) as row_number_rank
240
+
241
+ from INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
242
+ where tc.CONSTRAINT_TYPE in ('PRIMARY KEY', 'UNIQUE')
243
+ )
244
+ ,constraint_columns as (
234
245
select c.TABLE_SCHEMA
235
246
, c.TABLE_NAME
236
247
, c.COLUMN_NAME
248
+ , c.CONSTRAINT_NAME
237
249
238
250
from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE c
239
251
240
- join INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
252
+ join table_constraints tc
241
253
on tc.TABLE_SCHEMA = c.TABLE_SCHEMA
242
254
and tc.TABLE_NAME = c.TABLE_NAME
243
255
and tc.CONSTRAINT_NAME = c.CONSTRAINT_NAME
244
- and tc.CONSTRAINT_TYPE in ('PRIMARY KEY', 'UNIQUE'))
256
+ and tc.row_number_rank = 1
257
+ )
245
258
SELECT c.TABLE_SCHEMA,
246
259
c.TABLE_NAME,
247
260
c.COLUMN_NAME,
You can’t perform that action at this time.
0 commit comments