I'm trying to create a PostgreSQL trigger that updates a row whenever there's a change in some specific values.
I have a table which is has info about users, (user_code, user_email, user_name, user_password, and a field called password_reset).
My goal would be updating the password_reset field to the value "Y" and the user_password field to the value "123456", but just when there's any change in the user_name or user_email fields. I would like this to happen in the specific row where the change has been made. I've used an AFTER UPDATE trigger.
However, the whole table is updated instead of the row I want.
WHERE NEW.user_name IS DISTINCT FROM OLD.user_name. TheIFtest already established they are so theWHEREwill always evaluate true and since you have no other conditions on theWHEREall the rows willUPDATE.