File tree Expand file tree Collapse file tree 2 files changed +28
-24
lines changed Expand file tree Collapse file tree 2 files changed +28
-24
lines changed Original file line number Diff line number Diff line change @@ -17,10 +17,7 @@ SELECT
17
17
pg_stat_get_live_tuples(c .oid ) AS live_rows_estimate,
18
18
pg_stat_get_dead_tuples(c .oid ) AS dead_rows_estimate,
19
19
obj_description(c .oid ) AS comment,
20
- coalesce(
21
- jsonb_agg(primary_keys) filter (where primary_keys is not null ),
22
- ' []'
23
- ) as primary_keys,
20
+ coalesce(pk .primary_keys , ' []' ) as primary_keys,
24
21
coalesce(
25
22
jsonb_agg(relationships) filter (where relationships is not null ),
26
23
' []'
30
27
JOIN pg_class c ON nc .oid = c .relnamespace
31
28
left join (
32
29
select
33
- n .nspname as schema,
34
- c .relname as table_name,
35
- a .attname as name,
36
- c .oid :: int8 as table_id
37
- from
38
- pg_index i,
39
- pg_class c,
40
- pg_attribute a,
41
- pg_namespace n
42
- where
43
- i .indrelid = c .oid
44
- and c .relnamespace = n .oid
45
- and a .attrelid = c .oid
46
- and a .attnum = any (i .indkey )
47
- and i .indisprimary
48
- ) as primary_keys
49
- on primary_keys .table_id = c .oid
30
+ table_id,
31
+ jsonb_agg(_pk.* ) as primary_keys
32
+ from (
33
+ select
34
+ n .nspname as schema,
35
+ c .relname as table_name,
36
+ a .attname as name,
37
+ c .oid :: int8 as table_id
38
+ from
39
+ pg_index i,
40
+ pg_class c,
41
+ pg_attribute a,
42
+ pg_namespace n
43
+ where
44
+ i .indrelid = c .oid
45
+ and c .relnamespace = n .oid
46
+ and a .attrelid = c .oid
47
+ and a .attnum = any (i .indkey )
48
+ and i .indisprimary
49
+ ) as _pk
50
+ group by table_id
51
+ ) as pk
52
+ on pk .table_id = c .oid
50
53
left join (
51
54
select
52
55
c .oid :: int8 as id,
@@ -91,4 +94,5 @@ group by
91
94
c .relrowsecurity ,
92
95
c .relforcerowsecurity ,
93
96
c .relreplident ,
94
- nc .nspname
97
+ nc .nspname ,
98
+ pk .primary_keys
Original file line number Diff line number Diff line change @@ -465,12 +465,12 @@ test('primary keys', async () => {
465
465
"name": "t",
466
466
"primary_keys": [
467
467
{
468
- "name": "cc ",
468
+ "name": "c ",
469
469
"schema": "public",
470
470
"table_name": "t",
471
471
},
472
472
{
473
- "name": "c ",
473
+ "name": "cc ",
474
474
"schema": "public",
475
475
"table_name": "t",
476
476
},
You can’t perform that action at this time.
0 commit comments