[postgis-users] Fwd: Trigger Function Only for Updated Row.

Vera Green vera.green.ca at gmail.com
Mon Apr 4 08:28:13 PDT 2022


Hello,

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.

Here is my current code.

CREATE OR REPLACE FUNCTION public.pmap_tdl_loads_trucks()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$
BEGIN
NEW.truck =
CASE
    WHEN (NEW.load_vol < 15) THEN '90 Barrel Truck'
    WHEN (NEW.load_vol < 16) THEN '100 Barrel Truck'
    WHEN (NEW.load_vol < 18) THEN '110 Barrel Truck'
else 'Unknown Truck'
END;
    RETURN NEW;
END;
$BODY$;

CREATE TRIGGER update_truck
    BEFORE INSERT OR UPDATE
    ON public.tdl_water_loads
    FOR EACH ROW
    EXECUTE FUNCTION public.pmap_tdl_loads_trucks();

Thank you,
Vera
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20220404/c4b8ad58/attachment.html>


More information about the postgis-users mailing list