top of page
Волнистый абстрактный фон
CerebroSQL ico

Schema triggers in PostgreSQL database

Node displays information about triggers in schema in PostgreSQL database

PostgreSQL triggers list
  • Copy name - copy the name of the trigger to the clipboard

  • Enable trigger - generate a command to switch the trigger to the "Active" state

  • Disable trigger - generate a command to switch the trigger to the "Not used" state

  • Get DDL - form the text of the trigger and the function it calls

  • Drop trigger - generate a command to remove a trigger

List of triggers

select trg.tgname,
       CASE trg.tgtype::integer & 66
           WHEN 2 THEN 'BEFORE'
           WHEN 64 THEN 'INSTEAD OF'
           ELSE 'AFTER'
       end as trigger_type,
       case trg.tgtype::integer & cast(28 as int2)
          when 16 then 'UPDATE'
          when 8 then 'DELETE'
          when 4 then 'INSERT'
          when 20 then 'INSERT, UPDATE'
          when 28 then 'INSERT, UPDATE, DELETE'
          when 24 then 'UPDATE, DELETE'
          when 12 then 'INSERT, DELETE'
       end as trigger_event,
      ns.nspname||'.'||tbl.relname as trigger_table,
      obj_description(trg.oid) as remarks,
         when trg.tgenabled='O' then 'ENABLED'
           else 'DISABLED'
       end as status,
       case trg.tgtype::integer & 1
         when 1 then 'ROW'::text
         else 'STATEMENT'::text
       end as trigger_level,
FROM pg_trigger trg
JOIN pg_class tbl on trg.tgrelid = tbl.oid
JOIN pg_namespace ns ON ns.oid = tbl.relnamespace
 WHERE  ns.nspname = $$SCHEMANAME


select p.prosrc,
      pg_get_functiondef(p.oid) "def"
 from pg_catalog.pg_trigger t, pg_catalog.pg_proc p
where p.oid=t.tgfoid 
   and t.oid = $$TRIGGEROID  
SELECT pg_catalog.pg_get_triggerdef(t.oid, true) "ddl"
 FROM pg_catalog.pg_trigger t

bottom of page