I have a Postgresql Trigger, see below. My problem is when I add a new row and set the officer role to USER and the priority of request to HIGH I should get Not Authorized but I get Authorized. When I update the row the trigger fire and change the cell to Not Authorized. Is there anybody who is understand this and can provide me a solution? :) Why does it not work with insert and work with update?
CREATE OR REPLACE FUNCTION priority_authorization() RETURNS trigger AS $BODY$
BEGIN
IF ((NEW.t_officer_role = 'USER') AND (NEW.priority_of_request = 'HIGH'))THEN
NEW.t_priority_auth :='NOT AUTHORIZED';
ELSEIF NEW.t_officer_role = 'INVALID' THEN
NEW.t_priority_auth :='NOT AUTHORIZED';
ELSE
NEW.t_priority_auth :='AUTHORIZED';
END IF;
RETURN NEW;
END; $BODY$ LANGUAGE plpgsql VOLATILE;
CREATE TRIGGER priority_authorization_trigger BEFORE INSERT OR UPDATE ON durs_centroid
FOR EACH ROW
EXECUTE PROCEDURE priority_authorization();