Aftre更新删除行

时间:2016-10-21 19:13:20

标签: postgresql

我的下表名为'second'

   TABLE public.second
  (
  userid bigint,
  companyid bigint
    )

和表名为visibility_matrix

 CREATE TABLE public.visibility_matrix
(
   name character varying,
   companyid bigint
 )

我在更新'second'表后创建了一个触发器我想要删除可见性矩阵中的行,我试图通过在visibility_matrix中删除带有companyid的行来实现它,但它没有用,有什么建议吗?这是触发器:

创建或替换功能pos_org_rel_refresh()       RETURNS触发AS

$$  
  DECLARE
  r Integer ;

BEGIN  


IF TG_OP='UPDATE' THEN

DELETE FROM visibility_matrix where companyid=NEW.companyid;
END IF;


  END;
$$  
LANGUAGE 'plpgsql';  

  CREATE TRIGGER test_trigger  
  AFTER UPDATE OR DELETE
  ON second
  FOR EACH ROW  
  EXECUTE PROCEDURE pos_org_rel_refresh();

1 个答案:

答案 0 :(得分:0)

你错过了一个返回语句,这应该解决它:

CREATE OR REPLACE FUNCTION pos_org_rel_refresh() RETURNS trigger AS

$$  
  DECLARE
  r Integer ;

BEGIN  


IF TG_OP='UPDATE' THEN

    DELETE FROM visibility_matrix where companyid=NEW.companyid;
    RETURN NEW;
END IF;

RETURN NULL;
END;
$$  
LANGUAGE 'plpgsql';