1
+ SELECT
2
+ idx .indexrelid ::int8 AS id,
3
+ idx .indrelid ::int8 AS table_id,
4
+ n .nspname AS schema,
5
+ idx .indnatts AS number_of_attributes,
6
+ idx .indnkeyatts AS number_of_key_attributes,
7
+ idx .indisunique AS is_unique,
8
+ idx .indisprimary AS is_primary,
9
+ idx .indisexclusion AS is_exclusion,
10
+ idx .indimmediate AS is_immediate,
11
+ idx .indisclustered AS is_clustered,
12
+ idx .indisvalid AS is_valid,
13
+ idx .indcheckxmin AS check_xmin,
14
+ idx .indisready AS is_ready,
15
+ idx .indislive AS is_live,
16
+ idx .indisreplident AS is_replica_identity,
17
+ idx .indkey AS key_attributes,
18
+ idx .indcollation AS collation,
19
+ idx .indclass AS class,
20
+ idx .indoption AS options,
21
+ idx .indpred AS index_predicate,
22
+ obj_description(idx .indexrelid , ' pg_class' ) AS comment,
23
+ ix .indexdef as index_definition,
24
+ am .amname AS access_method,
25
+ jsonb_agg(
26
+ jsonb_build_object(
27
+ ' attribute_number' , a .attnum ,
28
+ ' attribute_name' , a .attname ,
29
+ ' data_type' , format_type(a .atttypid , a .atttypmod )
30
+ )
31
+ ORDER BY a .attnum
32
+ ) AS index_attributes
33
+ FROM
34
+ pg_index idx
35
+ JOIN pg_class c ON c .oid = idx .indexrelid
36
+ JOIN pg_namespace n ON c .relnamespace = n .oid
37
+ JOIN pg_am am ON c .relam = am .oid
38
+ JOIN pg_attribute a ON a .attrelid = c .oid AND a .attnum = ANY(idx .indkey )
39
+ JOIN pg_indexes ix ON c .relname = ix .indexname
40
+ GROUP BY
41
+ idx .indexrelid , idx .indrelid , n .nspname , idx .indnatts , idx .indnkeyatts , idx .indisunique , idx .indisprimary , idx .indisexclusion , idx .indimmediate , idx .indisclustered , idx .indisvalid , idx .indcheckxmin , idx .indisready , idx .indislive , idx .indisreplident , idx .indkey , idx .indcollation , idx .indclass , idx .indoption , idx .indexprs , idx .indpred , ix .indexdef , am .amname
0 commit comments