Postgresql function for detecting alerts
If I'm understanding the question correctly?

I would run the alert code in a Insert Trigger, and I would  add a column to measurement_tab to track which alerts matched the measurement.

alter table measurement_tab add column trigger_alert_id integer[];

CREATE TRIGGER alert
BEFORE INSERT
ON measurement_tab
FOR EACH ROW
EXECUTE PROCEDURE _alert();

CREATE FUNCTION _alert()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$

declare _r record;

begin

for _r in select id from alert_tab 
        where alert_tab.room_id = measurement_tab.room_id
        and value &lt; alert_value;
     new.trigger_alert_id = array_append(new.trigger_alert_id, _r.id);
end loop;

for _r in select id from alert_tab 
        where alert_tab.room_id = measurement_tab.room_id
        and value &gt; alert_value;
     new.trigger_alert_id = array_append(new.trigger_alert_id, _r.id);
end loop;

Run_alert_function(new.trigger_alert_id);  
         # this is where the other alert code 
         # that emails/sends out the alerts gets fired off; 
return new;
end;

$BODY$


If there is need to block alerts that have already been triggered.  Meaning once alert has been set it must be reset before it can be fired off again,   this can be done with additional logic in the loop,  that looks for previous entries in measurement_tab that set this alert previously.