DELETE trigger function
CREATE OR REPLACE FUNCTION fd_person() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN -- Confirm that history shows FR_person has been called IF NOT exists ( SELECT * FROM person_hst h WHERE h.person_id = OLD.person_id AND h.effective_until = 'infinity' AND removed ) THEN RAISE EXCEPTION 'Use fr_person() to delete person records'; END IF; -- Allow the delete to proceed RETURN OLD; END; $function$ ;