I am trying to make a trigger that updates the table files when a new record is inserted into table files_from_sass. So far i have the following function and trigger:
CREATE or replace FUNCTION update_child() RETURNS trigger AS $BODY$ BEGIN status = NEW.status IF NEW.status is NULL then RAISE Exception 'status cannot be null'; END IF; UPDATE files set sass_result = NEW.status WHERE sass_uid = NEW.sass_uid; RETURN NEW; END $BODY$ LANGUAGE plpgsql; DROP TRIGGER update_child_after_update on files_from_sass; CREATE TRIGGER update_child_after_update AFTER INSERT ON files_from_sass FOR EACH ROW EXECUTE PROCEDURE update_child();
The problem is that after insert the field sas_uid is updated but an error is raised for the field sass_result=NEW.status.
I’ve check the table files_from_sass and the field status is set, however the variable NEW.status is NULL.
What is the reason for this error ?