1
How to disable Trigger from all my tables in postgresql?
1
How to disable Trigger from all my tables in postgresql?
1
You can write a stored Procedure capable of enabling or disabling all triggers of all tables of a given schema, look at you:
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 the triggers of schema public:
SELECT fc_habilitar_triggers('public', TRUE );
Disabling all of the triggers of schema public:
SELECT fc_habilitar_triggers('public', FALSE );
0
ALTER TABLE tblname DISABLE TRIGGER USER
This should solve your problem. It has been marked as accepted in this answer of SOEN; there are some more alternatives, in case you want to take a look.
Browser other questions tagged sql database postgresql
You are not signed in. Login or sign up in order to post.