You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// | 2 | users | name | text | NO | false | false | |
@@ -23,18 +23,18 @@ SELECT
23
23
pg_attribute.attname AS column_name,
24
24
pg_catalog.format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS data_type,
25
25
CASE
26
-
WHEN conkey IS NOT NULL AND array_position(conkey, pg_attribute.attnum) > 0 THEN true
26
+
WHEN conkey IS NOT NULL AND contype = 'p' AND array_position(conkey, pg_attribute.attnum) > 0 THEN true
27
27
ELSE false
28
28
END AS is_primary_key,
29
29
CASE
30
30
WHEN pg_attribute.attnotnull THEN true
31
31
ELSE false
32
32
END AS not_null,
33
33
CASE
34
-
WHEN pg_index.indisunique THEN true
35
-
ELSE false
36
-
END AS is_unique,
37
-
COALESCE(pg_constraint.conname, '') AS primary_key_constraint_name
34
+
WHEN conkey IS NOT NULL AND (contype = 'p' OR contype = 'u') AND array_position(conkey, pg_attribute.attnum) > 0 THEN true
35
+
ELSE false
36
+
END AS is_unique,
37
+
COALESCE(pg_constraint.conname, '') AS constraint_name
38
38
FROM
39
39
pg_catalog.pg_attribute
40
40
INNER JOIN
@@ -44,9 +44,7 @@ FROM
44
44
LEFT JOIN
45
45
pg_catalog.pg_constraint ON pg_constraint.conrelid = pg_attribute.attrelid
46
46
AND conkey IS NOT NULL AND array_position(conkey, pg_attribute.attnum) > 0
47
-
AND contype = 'p'
48
-
LEFT JOIN pg_catalog.pg_index ON pg_index.indrelid = pg_attribute.attrelid
49
-
AND pg_index.indkey::text LIKE '%%' || pg_attribute.attnum || '%%'
47
+
AND (contype = 'p' OR contype = 'u')
50
48
INNER JOIN
51
49
information_schema.columns ON columns.table_name = pg_class.relname AND columns.column_name = pg_attribute.attname AND columns.table_schema = pg_catalog.pg_namespace.nspname
0 commit comments