PostgreSQLのpg_triggerからトリガ情報を取得する

SELECT tab.relname AS テーブル名,
       tg.tgname   AS トリガ名,
       tgf.proname AS トリガ関数名,
       CASE SUBSTRING( tg.tgtype::int::bit(8)::varchar FROM 7 FOR 1 )
            WHEN '1' THEN 'BEFORE' ELSE 'AFTER' END AS 作動タイミング,
       CASE SUBSTRING( tg.tgtype::int::bit(8)::varchar FROM 6 FOR 1 )
            WHEN '1' THEN true     ELSE false   END AS INSERT,
       CASE SUBSTRING( tg.tgtype::int::bit(8)::varchar FROM 5 FOR 1 )
            WHEN '1' THEN true     ELSE false   END AS DELETE,
       CASE SUBSTRING( tg.tgtype::int::bit(8)::varchar FROM 4 FOR 1 )
            WHEN '1' THEN true     ELSE false   END AS UPDATE
  FROM pg_trigger tg
  JOIN pg_class tab on tg.tgrelid = tab.oid
  JOIN pg_proc  tgf on tg.tgfoid  = tgf.oid
 WHERE tg.tgisinternal = false
   AND tab.relname     = '[テーブル名]'
 ORDER BY tab.relname, tg.tgname;

tgtype渋い。全然ドキュメントがない。

stackoverflow.com

The source code says:

41 int16 tgtype; / BEFORE/AFTER/INSTEAD, UPDATE/DELETE/INSERT, 42 * ROW/STATEMENT; see below /

93 / Bits within tgtype / 94 #define TRIGGER_TYPE_ROW (1 << 0) 95 #define TRIGGER_TYPE_BEFORE (1 << 1) 96 #define TRIGGER_TYPE_INSERT (1 << 2) 97 #define TRIGGER_TYPE_DELETE (1 << 3) 98 #define TRIGGER_TYPE_UPDATE (1 << 4) 99 #define TRIGGER_TYPE_TRUNCATE (1 << 5) 100 #define TRIGGER_TYPE_INSTEAD (1 << 6) 101 102 #define TRIGGER_TYPE_LEVEL_MASK (TRIGGER_TYPE_ROW) 103 #define TRIGGER_TYPE_STATEMENT 0