In my PostgreSQL 9.6 database, I am trying to update 2 fields in
table2 with a trigger when
table1 is modified.
CREATE OR REPLACE FUNCTION schema.maj_tbl2() RETURNS trigger AS $BODY$ begin UPDATE schema.table2 SET (contributor, code_tranche) = (user, table1.code_tranche) from schema.table1 where NEW.gid = table2.gid; return NEW; END; $BODY$
CREATE TRIGGER trg_maj_table2 BEFORE UPDATE ON schema.table1 FOR EACH ROW EXECUTE PROCEDURE schema.maj_tbl2();
The 2 fields in
table2 are modified the same way but for the entire table with the sames values. I can't update just the row in
table2 concerned by the update in
table1. I feel something is wrong with the
where condition but can't fix it.