Retrouver un trigger à partir du nom de la fonction associée
Par Orgrim le jeudi 7 avril 2011, 14:08 - PostgreSQL - Lien permanent
Ici encore, tout est dans le catalogue système de PostgreSQL, il suffit de regarder dans la table pg_trigger.
Avec les jointures qui vont bien, on peut obtenir les informations intéressantes :
SELECT nspname AS schema, relname AS TABLE, tgname AS TRIGGER, proname AS FUNCTION FROM pg_trigger t JOIN pg_class c ON (t.tgrelid = c.oid) JOIN pg_namespace n ON (n.oid = c.relnamespace) JOIN pg_proc p ON (p.oid = t.tgfoid);
En ajoutant une clause WHERE, on peut facilement retrouver la table associée au trigger :
SELECT nspname AS schema, relname AS TABLE, tgname AS TRIGGER, proname AS FUNCTION FROM pg_trigger t JOIN pg_class c ON (t.tgrelid = c.oid) JOIN pg_namespace n ON (n.oid = c.relnamespace) JOIN pg_proc p ON (p.oid = t.tgfoid) WHERE proname = 'mafonction';
Commentaires