KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to update a table according to this trigger: CREATE TRIGGER alert AFTER UPDATE ON cars FOR EACH ROW EXECUTE PROCEDURE update_cars(); Trigger Function : CREATE FUNCTION update_cars() RETURNS 'TRIGGER' AS $BODY$ BEGIN IF (TG_OP = 'UPDATE') THEN UPDATE hello_cars SET status = new.status WHERE OLD.ID = NEW.ID; END IF; RETURN NULL; END; $$ LANGUAGE plpgsql; The trigger works fine. When the cars table is updated, the hello_cars table is updated but the status column in each row is updated and contains same new status! It must be updated according to a car ID. I think my problem is in condition: WHERE OLD.ID = NEW.ID; but I can't tell what's wrong. Thanks in advance.
Tags (comma-separated)
Save Edits
Cancel