SELECT DISTINCT n.nspname as pnspname, n2.nspname as fnspname,
	c.relname as prelname, c2.relname as frelname,
	t.tgconstrname, a.attnum as keyseq, ic.relname as fkeyname,
	t.tgdeferrable, t.tginitdeferred, t.tgnargs,t.tgargs,
	p1.proname as updaterule, p2.proname as deleterule

FROM pg_catalog.pg_namespace n,
	pg_catalog.pg_namespace n2,
	pg_catalog.pg_trigger t,
	pg_catalog.pg_trigger t1,
	pg_catalog.pg_class c,
	pg_catalog.pg_class c2,
	pg_catalog.pg_class ic,
	pg_catalog.pg_proc p1,
	pg_catalog.pg_proc p2,
	pg_catalog.pg_index i,
	pg_catalog.pg_attribute a

WHERE 
	(t.tgrelid=c.oid AND t.tgisconstraint AND t.tgconstrrelid=c2.oid
		AND t.tgfoid=p1.oid and p1.proname like 'RI\_FKey\_%\_upd')
	AND
	(t1.tgrelid=c.oid and t1.tgisconstraint and t1.tgconstrrelid=c2.oid
		AND t1.tgfoid=p2.oid and p2.proname like 'RI\_FKey\_%\_del')
	AND i.indrelid=c.oid
	AND i.indexrelid=ic.oid
	AND ic.oid=a.attrelid
	AND i.indisprimary
	AND c.relnamespace = n.oid
	AND c2.relnamespace=n2.oid
	AND c2.relname='users'

ORDER BY prelname,keyseq
;

