<div dir="ltr"><div class="gmail_quote"><div dir="ltr">Hello,<div><br></div><div>Currently my trigger executes on ALL the rows in the table. I would like it to execute ONLY on the UPDATED row. My thinking is that it is inefficient to check all rows in a large table every time a single field is updated. My main reason for wanting to do this is for efficient processing.</div><div><br></div><div>Here is my current code. </div><div><br></div><div><font face="monospace">CREATE OR REPLACE FUNCTION public.pmap_tdl_loads_trucks()<br> RETURNS trigger<br> LANGUAGE 'plpgsql'<br> COST 100<br> VOLATILE NOT LEAKPROOF<br>AS $BODY$<br>BEGIN<br>NEW.truck = <br> CASE<br> WHEN (NEW.load_vol < 15) THEN '90 Barrel Truck'<br> WHEN (NEW.load_vol < 16) THEN '100 Barrel Truck'<br> WHEN (NEW.load_vol < 18) THEN '110 Barrel Truck'<br> else 'Unknown Truck'<br> END;<br> RETURN NEW; <br>END;<br>$BODY$;<br><br>CREATE TRIGGER update_truck<br> BEFORE INSERT OR UPDATE <br> ON </font><span style="font-family:monospace">public.</span><span style="font-family:monospace">tdl_water_loads</span></div><div><font face="monospace"> FOR EACH ROW<br> EXECUTE FUNCTION public.pmap_tdl_loads_trucks(); </font> <br></div><div><br></div><div>Thank you,</div><div>Vera</div></div>
</div></div>