File tree Expand file tree Collapse file tree 1 file changed +20
-23
lines changed Expand file tree Collapse file tree 1 file changed +20
-23
lines changed Original file line number Diff line number Diff line change 32
32
JOIN pg_class c ON nc.oid = c.relnamespace
33
33
left join (
34
34
select
35
- table_id,
36
- jsonb_agg(_pk.*) as primary_keys
37
- from (
38
- select
39
- n.nspname as schema,
40
- c.relname as table_name,
41
- a.attname as name,
42
- c.oid :: int8 as table_id
43
- from
44
- pg_index i,
45
- pg_class c,
46
- pg_attribute a,
47
- pg_namespace n
48
- where
49
- ${ props . schemaFilter ? `n.nspname ${ props . schemaFilter } AND` : '' }
50
- ${ props . tableIdentifierFilter ? `n.nspname || '.' || c.relname ${ props . tableIdentifierFilter } AND` : '' }
51
- i.indrelid = c.oid
52
- and c.relnamespace = n.oid
53
- and a.attrelid = c.oid
54
- and a.attnum = any (i.indkey)
55
- and i.indisprimary
56
- ) as _pk
57
- group by table_id
35
+ c.oid::int8 as table_id,
36
+ jsonb_agg(
37
+ jsonb_build_object(
38
+ 'table_id', c.oid::int8,
39
+ 'schema', n.nspname,
40
+ 'table_name', c.relname,
41
+ 'name', a.attname
42
+ )
43
+ order by array_position(i.indkey, a.attnum)
44
+ ) as primary_keys
45
+ from
46
+ pg_index i
47
+ join pg_class c on i.indrelid = c.oid
48
+ join pg_namespace n on c.relnamespace = n.oid
49
+ join pg_attribute a on a.attrelid = c.oid and a.attnum = any(i.indkey)
50
+ where
51
+ ${ props . schemaFilter ? `n.nspname ${ props . schemaFilter } AND` : '' }
52
+ ${ props . tableIdentifierFilter ? `n.nspname || '.' || c.relname ${ props . tableIdentifierFilter } AND` : '' }
53
+ i.indisprimary
54
+ group by c.oid
58
55
) as pk
59
56
on pk.table_id = c.oid
60
57
left join (
You can’t perform that action at this time.
0 commit comments