Created
March 11, 2014 19:07
-
-
Save ianpgall/9492760 to your computer and use it in GitHub Desktop.
PostgreSQL function that deletes all triggers for all tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION strip_all_triggers() RETURNS text AS $$ DECLARE | |
triggNameRecord RECORD; | |
triggTableRecord RECORD; | |
BEGIN | |
FOR triggNameRecord IN select distinct(trigger_name) from information_schema.triggers where trigger_schema = 'public' LOOP | |
FOR triggTableRecord IN SELECT distinct(event_object_table) from information_schema.triggers where trigger_name = triggNameRecord.trigger_name LOOP | |
RAISE NOTICE 'Dropping trigger: % on table: %', triggNameRecord.trigger_name, triggTableRecord.event_object_table; | |
EXECUTE 'DROP TRIGGER ' || triggNameRecord.trigger_name || ' ON ' || triggTableRecord.event_object_table || ';'; | |
END LOOP; | |
END LOOP; | |
RETURN 'done'; | |
END; | |
$$ LANGUAGE plpgsql SECURITY DEFINER; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment