我是新来的波斯格雷斯.我找到了一个SQL,它几乎满足了我的需求,但我还没有弄清楚如何将表所有者作为结果集的一部分,以及如何在WHERE子句中使用表所有者.我将注释放在我需要的专栏引用的位置.以下是我的代码:
SELECT (select r.relname from pg_class r where r.oid = c.confrelid) as base_table,
a.attname as base_col,
--base table schema
(select r.relname from pg_class r where r.oid = c.conrelid) as referencing_table,
UNNEST((select array_agg(attname) from pg_attribute where attrelid = c.conrelid and array[attnum] <@ c.conkey)) as referencing_col
-- referenceing table schema
FROM pg_constraint c join pg_attribute a on c.confrelid=a.attrelid and a.attnum = ANY(confkey)
WHERE c.confrelid = (select oid from pg_class where relname = 'table_name')
-- and table_schema = 'schema_name'
AND c.confrelid!=c.conrelid;
任何帮助都将不胜感激.