trigger on 2 tables one to many Here are two tables :
table1

id1(pk) objectid z
0        1       100
1        2       98


table2

id2(pk) n_sd prof alt_inf
0        1   5
1        1   15
2        2   8


objectid -> n_sd (1->n).

The aim of the trigger is on insert on table2 to do the maths alt_inf = z-prof for objectid = n_sd.

IF (TG_OP = 'INSERT') THEN
NEW.alti_inf = (select z-NEW.prof from table1 join table2
on table2.n_sd = table1.objectid 
where new.gid = table2.gid )
RETURN NEW;
END IF ;

DROP TRIGGER IF EXISTS trg_calcul_altiinf ON table2 ;
CREATE TRIGGER trg_calcul_altiinf AFTER INSERT ON table2
FOR EACH ROW EXECUTE PROCEDURE calcul_altiInf();


I have no result nor error message.
In a trigger fired AFTER the insertion it makes no sense to modify the NEW record, as it has been already inserted. Use a BEFORE trigger.

CREATE TRIGGER trg_calcul_altiinf 
BEFORE INSERT OR UPDATE ON table2    -- + UPDATE
FOR EACH ROW EXECUTE PROCEDURE calcul_altiInf();


In the function body you should query only the table1, as the current value of n_sd is in the NEW record:

IF TG_OP IN ('INSERT', 'UPDATE') THEN    -- + UPDATE
    NEW.alti_inf = (
        SELECT z - NEW.prof 
        FROM table1 
        WHERE NEW.n_sd = table1.objectid);
    RETURN NEW;
END IF;