How to disable the triggering of all my tables in postgreSQL?
How to disable the triggering of all my tables in postgreSQL?
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 );
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.