Deleting rows from child table without deleting from parent I have 2 tables, connected with inheritance.
I want to delete some rows from the child table. The deletion part works but it deletes rows from the parent as well:
CREATE OR REPLACE FUNCTION earthquakes_trigger()
RETURNS TRIGGER AS $$
BEGIN
    INSERT INTO earthquakes VALUES (NEW.*);
    DELETE FROM ONLY earthquakes WHERE datetime &lt; (now() - '2 days'::interval);
    RETURN NULL;
END;
$$
LANGUAGE plpgsql;

CREATE TRIGGER earthquakes_trigger
        BEFORE INSERT ON earthquakes_ovr
        FOR EACH ROW EXECUTE PROCEDURE earthquakes_trigger();

Parent table : earthquakes_ovr
Child table: earthquakes
I also tried to break up the trigger function, and have the deletion part as trigger function on the child, but that didn't work either.
As you can see that is not the case, when  the tables are not linked in anyway


CREATE tABLE earthquakes_ovr (&quot;datetime&quot; timestamp)




INSERT INTO earthquakes_ovr VALUES (NOW() - INTERVAL '6 DAYS')




INSERT INTO earthquakes_ovr VALUES (now() - INTERVAL'4 days')




CREATE UNLOGGED TABLE  earthquakes AS SELECT * FROM earthquakes_ovr




    CREATE OR REPLACE FUNCTION earthquakes_trigger()
    RETURNS TRIGGER AS $$
    BEGIN
        INSERT INTO earthquakes VALUES (NEW.*);
        DELETE FROM ONLY earthquakes WHERE datetime &lt; (now() - '2 days'::interval);
        RETURN NEW;
    END;
    $$
    LANGUAGE plpgsql;
    
    CREATE TRIGGER earthquakes_trigger
            BEFORE INSERT ON earthquakes_ovr
            FOR EACH ROW EXECUTE PROCEDURE earthquakes_trigger();




INSERT INTO earthquakes_ovr VALUES (now())




SELECT * FROM earthquakes_ovr


| datetime                   |
| :------------------------- |
| 2021-04-18 00:11:15.191671 |
| 2021-04-20 00:11:15.203608 |
| 2021-04-24 00:11:15.267616 |




SELECT * FROM earthquakes


| datetime                   |
| :------------------------- |
| 2021-04-24 00:11:15.267616 |


db&lt;&gt;fiddle here