How to disable Trigger of all tables in PostgreSQL? [closed]

1

How to disable the triggering of all my tables in postgreSQL?

    
asked by anonymous 20.04.2018 / 03:55

2 answers

1

You can write a stored procedure to enable or disable all triggers of all tables in a particular schema , see:

CREATE FUNCTION fc_habilitar_triggers( nome_schema TEXT, habilitar BOOLEAN )
RETURNS VOID AS 
$BODY$
DECLARE
    tbl RECORD;
BEGIN
    FOR tbl IN SELECT schemaname || '.' || tablename AS nome FROM pg_tables WHERE schemaname = nome_schema
    LOOP
        IF ( habilitar = TRUE ) THEN
            RAISE NOTICE 'Habilitando Triggers da Tabela: %', tbl.nome;
            EXECUTE 'ALTER TABLE ' || tbl.nome || ' ENABLE TRIGGER ALL';
        ELSE
            RAISE NOTICE 'Desabilitando Triggers da Tabela: %', tbl.nome;
            EXECUTE 'ALTER TABLE ' || tbl.nome || ' DISABLE TRIGGER ALL';
        END IF;
    END LOOP;

    RETURN;
END;
$BODY$
LANGUAGE 'plpgsql';

Enabling all triggers of the schema public :

SELECT fc_habilitar_triggers('public', TRUE );

Disabling all triggers public :

SELECT fc_habilitar_triggers('public', FALSE );
    
20.04.2018 / 15:00
0
ALTER TABLE tblname DISABLE TRIGGER USER

This should solve your problem. Has been marked accepted in this answer of SOEN ; there are a few more alternatives if you want to take a look.

    
20.04.2018 / 15:05