1 -- ---- Here is a function that I use to list fk(triggers) on a table. Execute the
2 -- ---- function to get the trigger name and then - drop trigger "trigger_name" on
4 -- -- Version 1.0, June 2002
6 -- -- Function lists FK by table.
8 -- -- begin;select fn_list_fk('table_name');
9 -- -- fetch all from "<cursor_name>"; end;
10 -- create or replace function fn_list_fk(name)
11 -- returns refcursor as
14 -- table_in alias for $1;
18 -- select tgname as trigger_name_sys
19 -- ,tgconstrname as trigger_name_given
20 -- ,b.relname as table_name
21 -- ,tgisconstraint as ri
22 -- ,c.relname as parent_table
26 -- where a.tgrelid=b.oid and b.relname=table_in
27 -- and tgconstrrelid = c.oid;
33 -- select tgname as trigger_name_sys, tgconstrname as trigger_name_given, b.relname as table_name ,tgisconstraint as ri ,c.relname as parent_table from pg_trigger a, pg_class b, pg_class c where a.tgrelid=b.oid and b.relname=table_in and tgconstrrelid = c.oid;
34 -- For project_task table
35 select tgname as trigger_name_sys, tgconstrname as trigger_name_given, b.relname as table_name ,tgisconstraint as ri ,c.relname as parent_table from pg_trigger a, pg_class b, pg_class c where a.tgrelid=b.oid and b.relname='project_task' and tgconstrrelid = c.oid;