-- -- trigger_exists/2 -- create or replace function trigger_exists( character varying, character varying ) returns bool as $$ declare trigger_name alias for $1; on_table alias for $2; begin return count(*) > 0 from pg_class c, pg_trigger t where c.relname = lower(on_table) and c.oid = t.tgrelid and t.tgname = lower(trigger_name); end;$$ language plpgsql;