POSTGRESQL引发麻烦

时间:2018-11-06 17:03:03

标签: postgresql

编写此代码。这段代码的问题是它什么也不做。我在更新表格时应该更新OTB_Name,但是什么也没有发生。

有人可以告诉我我的问题在哪里吗?

CREATE OR REPLACE FUNCTION public.demand_lom_ar5_tracker() 
RETURNS trigger AS $demand_lom_ar5_tracker$
BEGIN
    -- INSERT
    IF (TG_OP = 'INSERT') THEN
        UPDATE public.demand_lom_ar5
            SET "OTB_Name" = ar5_area_otb."OTB_Name"
            FROM mapinfo.public.ar5_area_otb
            WHERE ST_Contains (mapinfo.public.demand_lom_ar5."SP_GEOMETRY", mapinfo.public.ar5_area_otb."SP_GEOMETRY");
        RETURN NULL;
    -- UPDATE
    ELSIF (TG_OP = 'UPDATE') THEN
        UPDATE public.demand_lom_ar5
            SET "OTB_Name" = ar5_area_otb."OTB_Name"
            FROM mapinfo.public.ar5_area_otb
            WHERE NEW."MI_PRINX" = OLD."MI_PRINX" and ST_Contains (mapinfo.public.demand_lom_ar5."SP_GEOMETRY", mapinfo.public.ar5_area_otb."SP_GEOMETRY");
        RETURN NULL;
    END IF;
END;

$demand_lom_ar5_tracker$ LANGUAGE plpgsql; 

--apply the trigger:
DROP TRIGGER IF EXISTS trg_demand_lom_ar5_tracker 
  ON public.demand_lom_ar5;

CREATE TRIGGER trg_demand_lom_ar5_tracker 
  AFTER INSERT OR UPDATE ON public.demand_lom_ar5
  FOR EACH ROW EXECUTE PROCEDURE public.demand_lom_ar5_tracker();

0 个答案:

没有答案