I have this Postgresql query:
select (select r.relname from pg_class r where r.oid = c.conrelid) as table,
(select r.relkind from pg_class r where r.oid = c.conrelid) as type,
(select array_agg(attname) from pg_attribute
where attrelid = c.conrelid and ARRAY[attnum] <@ c.conkey) as col,
(select r.relname from pg_class r where r.oid = c.confrelid) as ftable,
from pg_constraint c
where c.confrelid = (select oid from pg_class where relname = 'table name') and
c.confkey @> (select array_agg(attnum) from pg_attribute
where attname = 'column name' and attrelid = c.confrelid)
which for a specific fk from a specific table it will present the other tables that associated to this key. This query is working fine…
My goal is to 2 things:
- add a column which contains the schema of the tables
- this query present only tables… how do i add views? – SOLVED
I know it’s something simple probably with pg_class but i don’t know how to resolve this.