How do I know if a trigger is enabled in PostgreSQL?

My googling-fu is failing. How do I know if a PostgreSQL trigger is disabled or not?

+5
source share
3 answers

This is my first day with postresql, but I think you can check the trigger status through the pg_trigger system table: http://www.postgresql.org/docs/current/static/catalog-pg-trigger.html

You need columns tgrelidand tgenabled.

+8
source

The SQL below will do the job. It displays all the triggers in the current database.

SELECT pg_namespace.nspname, pg_class.relname, pg_trigger.*
FROM pg_trigger
JOIN pg_class ON pg_trigger.tgrelid = pg_class.oid
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace  

tgenabled - "D", . ( ) , - .

BTW. , :

SELECT * FROM pg_trigger
WHERE tgrelid = 'your_schema.your_table'::regclass

regclass OID (object id).

+2
SELECT EXISTS (
    SELECT  tgenabled
    FROM    pg_trigger
    WHERE   tgname='your_unique_trigger_name' AND
            tgenabled != 'D'
);

If you know that the trigger name is unique, the above will return true (t) if your_unique_trigger_name trigger is enabled:

 exists
--------
 t
(1 row)

If disabled, it will return false (f).

+2
source

All Articles