@@ -26,6 +26,7 @@ def get_table_list(self) -> list[Table]:
26
26
c.data_type,
27
27
c.is_nullable,
28
28
c.ordinal_position,
29
+ tc.constraint_type,
29
30
obj_description(cls.oid) AS table_comment,
30
31
col_description(cls.oid, a.attnum) AS column_comment
31
32
FROM
@@ -44,6 +45,12 @@ def get_table_list(self) -> list[Table]:
44
45
pg_attribute a
45
46
ON a.attrelid = cls.oid
46
47
AND a.attname = c.column_name
48
+ LEFT JOIN information_schema.key_column_usage kcu
49
+ ON c.table_name = kcu.table_name
50
+ AND c.column_name = kcu.column_name
51
+ AND c.table_schema = kcu.table_schema
52
+ LEFT JOIN information_schema.table_constraints tc
53
+ ON kcu.constraint_name = tc.constraint_name
47
54
WHERE
48
55
t.table_type IN ('BASE TABLE', 'VIEW')
49
56
AND t.table_schema NOT IN ('information_schema', 'pg_catalog');
@@ -67,7 +74,7 @@ def get_table_list(self) -> list[Table]:
67
74
catalog = row ["table_catalog" ],
68
75
table = row ["table_name" ],
69
76
),
70
- primaryKey = "" ,
77
+ primaryKey = [] ,
71
78
)
72
79
73
80
# table exists, and add column to the table
@@ -80,6 +87,10 @@ def get_table_list(self) -> list[Table]:
80
87
properties = None ,
81
88
)
82
89
)
90
+
91
+ if row ["constraint_type" ] == 'PRIMARY KEY' :
92
+ unique_tables [schema_table ].primaryKey .append (row ["column_name" ])
93
+
83
94
return list (unique_tables .values ())
84
95
85
96
def get_constraints (self ) -> list [Constraint ]:
0 commit comments