如果你有触发器,在 postgres 中

in postgrers if you have a trigger

说它被解雇了

after insert or update

有没有办法知道真正发生的事情

例如 插入 table x .... 然后触发的触发器说 'IT WAS AN INSERT' 更新 x .... 然后触发触发器说 'IT WAS AN UPDATE'

是的,我可以拆分它们

示例:

CREATE OR REPLACE FUNCTION log_table1() 
returns trigger
language plpgsql
AS $$
begin
    
    IF (TG_OP = 'DELETE') THEN
            INSERT INTO tbl_status (state) values ('DELETE RECORD');
            RETURN OLD;
    ELSIF (TG_OP = 'UPDATE') THEN
            INSERT INTO tbl_status (state) values ('UPDATE RECORD');
            RETURN NEW;
    ELSIF (TG_OP = 'INSERT') THEN
            INSERT INTO tbl_status (state) values ('INSERT NEW RECORD');
            RETURN NEW;
    END IF;
   
    RETURN NULL; 
        
end;
$$;


CREATE TRIGGER trigger_log_table1
before INSERT OR UPDATE OR DELETE 
ON table1
FOR EACH ROW
  EXECUTE PROCEDURE log_table1();