Hello all,
This is a rather difficult question but I'm sure someone's probably figured this out, has anyone been able to pull foreign key information from Postgresql's system tables? I found a query that does most of what I want it to do, it retrieves the foreign key name, and the columns that are linked. The only problem is that it does not give me the name of the foreign table (I already have the base table name). Here is the query:
Any suggestions or help is greatly appreciated.
Thanks!
Jisoo23
This is a rather difficult question but I'm sure someone's probably figured this out, has anyone been able to pull foreign key information from Postgresql's system tables? I found a query that does most of what I want it to do, it retrieves the foreign key name, and the columns that are linked. The only problem is that it does not give me the name of the foreign table (I already have the base table name). Here is the query:
Code:
SELECT pt.tgargs FROM pg_class pc, pg_proc pg_proc, pg_proc pg_proc_1, pg_trigger pg_trigger, pg_trigger pg_trigger_1, pg_proc pp, pg_trigger pt WHERE pt.tgrelid = pc.oid AND pp.oid = pt.tgfoid AND pg_trigger.tgconstrrelid = pc.oid AND pg_proc.oid = pg_trigger.tgfoid AND pg_trigger_1.tgfoid = pg_proc_1.oid AND pg_trigger_1.tgconstrrelid = pc.oid AND ((pc.relname= '<< TABLENAME >>>') AND (pp.proname LIKE '%%ins') AND (pg_proc.proname LIKE '%%upd') AND (pg_proc_1.proname LIKE '%%del') AND (pg_trigger.tgrelid=pt.tgconstrrelid) AND (pg_trigger_1.tgrelid = pt.tgconstrrelid));
Any suggestions or help is greatly appreciated.
Thanks!
Jisoo23