OLD
and NEW
are aliases for strings that trigger a trigger. Therefore, when you execute an operator like
UPDATE cars SET status='xyz' WHERE cars.id = 42;
then the trigger function will execute
UPDATE hello_cars SET status='xyz' WHERE 42 = 42
Part 42=42
always true. Therefore, each line in hello_cars
updated.
Do you really want something like
[...]WHERE hello_cars.id = OLD.ID
or a little shorter
[...]WHERE id = OLD.ID
But you also need to think about what happens if the initial update changes cars.id
In this case, OLD.ID
not equal to NEW.ID
What should happen in the hello_cars
table in this case? But this is another question.
source share