@@ -26,32 +26,22 @@ SELECT
2626 END
2727 END AS data_type,
2828 COALESCE(bt .typname , t .typname ) AS format,
29- CASE
30- WHEN a .attidentity IN (' a' , ' d' ) THEN TRUE
31- ELSE FALSE
32- END AS is_identity,
29+ a .attidentity IN (' a' , ' d' ) AS is_identity,
3330 CASE
3431 a .attidentity
3532 WHEN ' a' THEN ' ALWAYS'
3633 WHEN ' d' THEN ' BY DEFAULT'
3734 ELSE NULL
3835 END AS identity_generation,
39- CASE
40- WHEN a .attnotnull
41- OR t .typtype = ' d'
42- AND t .typnotnull THEN FALSE
43- ELSE TRUE
44- END AS is_nullable,
45- CASE
46- WHEN (
47- c .relkind IN (' r' , ' p' )
48- )
49- OR (
50- c .relkind IN (' v' , ' f' )
51- )
52- AND pg_column_is_updatable(c .oid , a .attnum , FALSE) THEN TRUE
53- ELSE FALSE
54- END AS is_updatable,
36+ NOT (
37+ a .attnotnull
38+ OR t .typtype = ' d' AND t .typnotnull
39+ ) AS is_nullable,
40+ (
41+ c .relkind IN (' r' , ' p' )
42+ OR c .relkind IN (' v' , ' f' ) AND pg_column_is_updatable(c .oid , a .attnum , FALSE)
43+ ) AS is_updatable,
44+ uniques .table_id IS NOT NULL AS is_unique,
5545 array_to_json(
5646 array(
5747 SELECT
8272 JOIN pg_namespace nbt ON bt .typnamespace = nbt .oid
8373 ) ON t .typtype = ' d'
8474 AND t .typbasetype = bt .oid
75+ LEFT JOIN (
76+ SELECT
77+ conrelid AS table_id,
78+ conkey[1 ] AS ordinal_position
79+ FROM pg_catalog .pg_constraint
80+ WHERE contype = ' u' AND cardinality(conkey) = 1
81+ ) AS uniques ON uniques .table_id = c .oid AND uniques .ordinal_position = a .attnum
8582WHERE
8683 NOT pg_is_other_temp_schema(nc .oid )
8784 AND a .attnum > 0
0 commit comments