CREATE TABLE parent(id integer, val text);
CREATE TABLE child() INHERITS (parent);

CREATE OR REPLACE FUNCTION inh_trigger() RETURNS trigger
   LANGUAGE plpgsql AS
$$BEGIN
   RAISE NOTICE 'Called by parent %', TG_OP;
   RETURN CASE WHEN TG_OP = 'DELETE' THEN OLD ELSE NEW END;
END;$$;

CREATE TRIGGER inh_trigger BEFORE INSERT OR UPDATE OR DELETE ON parent
   FOR EACH ROW EXECUTE PROCEDURE inh_trigger();

CREATE OR REPLACE FUNCTION inh_trigger2() RETURNS trigger
   LANGUAGE plpgsql AS
$$BEGIN
   RAISE NOTICE 'Called by child %', TG_OP;
   RETURN CASE WHEN TG_OP = 'DELETE' THEN OLD ELSE NEW END;
END;$$;

CREATE TRIGGER inh_trigger2 BEFORE INSERT OR UPDATE OR DELETE ON child
   FOR EACH ROW EXECUTE PROCEDURE inh_trigger2();

INSERT INTO parent VALUES (1, 'one');
INSERT INTO child VALUES (2, 'two');

UPDATE parent SET val = 'changed' WHERE id = 1;
UPDATE parent SET val = 'changed' WHERE id = 2;

DELETE FROM parent WHERE id = 1;
DELETE FROM parent WHERE id = 2;
