-- -- trigger_type/1 -- create or replace function trigger_type( integer ) returns varchar as $$ declare tgtype alias for $1; description varchar; sep varchar; begin if (tgtype & 2) > 0 then description := 'BEFORE '; else description := 'AFTER '; end if; sep := ''; if (tgtype & 4) > 0 then description := description || 'INSERT '; sep := 'OR '; end if; if (tgtype & 8) > 0 then description := description || sep || 'DELETE '; sep := 'OR '; end if; if (tgtype & 16) > 0 then description := description || sep || 'UPDATE '; sep := 'OR '; end if; if (tgtype & 1) > 0 then description := description || 'FOR EACH ROW'; else description := description || 'STATEMENT'; end if; return description; end;$$ language plpgsql;