如何在DB PostgreSql中禁用嵌套触发器?

时间:2018-04-27 12:41:23

标签: postgresql triggers

我执行以下命令:

INSERT INTO CSM_ACTUAL (SIGN_CODE,CREATE_DATE,CSM_NAME_ROD_CASE,CSM_NAME,CSM_CODE,CSM_NAME_SHORT,FTP_USER_NAME,SESS_ID) VALUES('6767',cast('2018-04-27 12:24:22' as timestamp),'6565','55665',10104,'56565','ftp_343',17);

以下触发器与此命令相关联:

CREATE TRIGGER CSM_INS INSTEAD OF INSERT ON CSM_ACTUAL FOR EACH ROW
EXECUTE PROCEDURE "TriggerFunctionCsmIns"();

以下功能与触发器相关联:

CREATE OR REPLACE FUNCTION "TriggerFunctionCsmIns"()
  RETURNS TRIGGER AS $$
  DECLARE INSERTED_ID INTEGER;
  DECLARE SESSION_ID INTEGER;
  DECLARE CHANGE_ID INTEGER;
BEGIN
  SESSION_ID = NEW.SESS_ID;
  SELECT "SetChangeBySessionId"(SESSION_ID) INTO CHANGE_ID;

  INSERTED_ID = (SELECT COALESCE (MAX(ID), 0) + 1 FROM CSM_ATTR WHERE ENTITY_ID = NEW.ENTITY_ID);

IF NOT EXISTS(SELECT * FROM CSM_FK WHERE CSM_CODE=NEW.CSM_CODE) THEN
    INSERT INTO CSM_FK(CSM_CODE) VALUES(NEW.CSM_CODE);
END IF;
INSERT INTO CSM_ATTR
(
ID, RECSTATE, SESS_ID, ENTITY_ID, CREATE_DATE,
DELETE_DATE, CREATION_ID, DELETION_ID, CSM_CODE, CSM_NAME,
ACCREDITATION_CODE, ACCREDITATION_DATE, ACCREDITATION_DATE_END, SIGN_CODE,
INN, KPP, OKPO, OKONH, OKATO, REGION, POSTCODE, ADDRESS, PHONE, FAX, E_MAIL,
DIRECTOR, DIRECTOR_DAT_CASE, DIRECTOR_ROD_CASE, DIRECTOR_POSITION,
DIRECTOR_POSITION_ROD_CASE, GLAVBUH, BANK, BIK, BANK_ACCOUNT, LORO_ACCOUNT,
BANK_BALANCE, OFK_NAME, OFK_INN, OFK_KPP, OFK_LACCOUNT, OFK_OKONH, OFK_OKPO,
MARK_DOC_NUM, MARK_DOC_DATE, MARK_DOC_DATE_END, CONTACT_PHONE, CONTACT_PERSON, AGENT_DOCNO,
AGENT_DOC_DATE, AGENT_DOC_EXPDATE, CSM_NAME_ROD_CASE, PARENT_CODE,
FTP_USER_NAME, LICENSES, LICENSE_SIGNATURE, CSM_NAME_SHORT
)
VALUES
(
INSERTED_ID, 1, NULL, INSERTED_ID, NEW.CREATE_DATE, NULL,
CHANGE_ID, NULL, NEW.CSM_CODE, NEW.CSM_NAME,
NEW.ACCREDITATION_CODE, NEW.ACCREDITATION_DATE,
NEW.ACCREDITATION_DATE_END, NEW.SIGN_CODE,
NEW.INN, NEW.KPP, NEW.OKPO,
NEW.OKONH, NEW.OKATO, NEW.REGION,
NEW.POSTCODE, NEW.ADDRESS, NEW.PHONE,
NEW.FAX, NEW.E_MAIL, NEW.DIRECTOR,
NEW.DIRECTOR_DAT_CASE, NEW.DIRECTOR_ROD_CASE,
NEW.DIRECTOR_POSITION,
NEW.DIRECTOR_POSITION_ROD_CASE, NEW.GLAVBUH,
NEW.BANK, NEW.BIK, NEW.BANK_ACCOUNT,
NEW.LORO_ACCOUNT, NEW.BANK_BALANCE,
NEW.OFK_NAME, NEW.OFK_INN,
NEW.OFK_KPP, NEW.OFK_LACCOUNT,
NEW.OFK_OKONH, NEW.OFK_OKPO,
NEW.MARK_DOC_NUM, NEW.MARK_DOC_DATE, NEW.MARK_DOC_DATE_END,
NEW.CONTACT_PHONE, NEW.CONTACT_PERSON,
NEW.AGENT_DOCNO, NEW.AGENT_DOC_DATE,
NEW.AGENT_DOC_EXPDATE, NEW.CSM_NAME_ROD_CASE,
NEW.PARENT_CODE, NEW.FTP_USER_NAME,
NEW.LICENSES, NEW.LICENSE_SIGNATURE, NEW.CSM_NAME_SHORT
);


INSERT INTO CSM_ATTR_LOG
(
ID,RECSTATE,SESS_ID,ENTITY_ID,CREATE_DATE,DELETE_DATE,CREATION_ID,DELETION_ID,CSM_CODE,CSM_NAME,
ACCREDITATION_CODE,ACCREDITATION_DATE,ACCREDITATION_DATE_END,SIGN_CODE,
INN,KPP,OKPO,OKONH,OKATO,REGION,POSTCODE,ADDRESS,PHONE,FAX,E_MAIL,
DIRECTOR,DIRECTOR_DAT_CASE,DIRECTOR_ROD_CASE,DIRECTOR_POSITION,
DIRECTOR_POSITION_ROD_CASE,GLAVBUH,BANK,BIK,BANK_ACCOUNT,LORO_ACCOUNT,
BANK_BALANCE,OFK_NAME,OFK_INN,OFK_KPP,OFK_LACCOUNT,OFK_OKONH,OFK_OKPO,
MARK_DOC_NUM,MARK_DOC_DATE,MARK_DOC_DATE_END,CONTACT_PHONE,CONTACT_PERSON,AGENT_DOCNO,
AGENT_DOC_DATE,AGENT_DOC_EXPDATE,CSM_NAME_ROD_CASE,PARENT_CODE,
FTP_USER_NAME,LICENSES,LICENSE_SIGNATURE,CSM_NAME_SHORT
)
VALUES
(INSERTED_ID, 1, NULL, INSERTED_ID, CURRENT_TIMESTAMP, NULL,
CHANGE_ID, NULL, NEW.CSM_CODE, NEW.CSM_NAME,
NEW.ACCREDITATION_CODE, NEW.ACCREDITATION_DATE,
NEW.ACCREDITATION_DATE_END, NEW.SIGN_CODE,
NEW.INN, NEW.KPP, NEW.OKPO,
NEW.OKONH, NEW.OKATO, NEW.REGION,
NEW.POSTCODE, NEW.ADDRESS, NEW.PHONE,
NEW.FAX, NEW.E_MAIL, NEW.DIRECTOR,
NEW.DIRECTOR_DAT_CASE, NEW.DIRECTOR_ROD_CASE,
NEW.DIRECTOR_POSITION,
NEW.DIRECTOR_POSITION_ROD_CASE, NEW.GLAVBUH,
NEW.BANK, NEW.BIK, NEW.BANK_ACCOUNT,
NEW.LORO_ACCOUNT, NEW.BANK_BALANCE,
NEW.OFK_NAME, NEW.OFK_INN,
NEW.OFK_KPP, NEW.OFK_LACCOUNT,
NEW.OFK_OKONH, NEW.OFK_OKPO,
NEW.MARK_DOC_NUM, NEW.MARK_DOC_DATE, NEW.MARK_DOC_DATE_END,
NEW.CONTACT_PHONE, NEW.CONTACT_PERSON,
NEW.AGENT_DOCNO, NEW.AGENT_DOC_DATE,
NEW.AGENT_DOC_EXPDATE, NEW.CSM_NAME_ROD_CASE,
NEW.PARENT_CODE, NEW.FTP_USER_NAME,
NEW.LICENSES, NEW.LICENSE_SIGNATURE, NEW.CSM_NAME_SHORT
);
return NEW;

END;
$$
LANGUAGE plpgsql;

触发器功能的文本显示,当您执行它时,您将插入CSM_ATTR表(TriggerFunctionCsmAttrIns触发器)并插入CSM_ATTR_LOG表(TriggerFunctionCsmAttrIns触发器)。

问题:我可以自定义PostgreSql,因此不存在来自其他触发器的级联触发器吗?

在MS SQL Server中

P.S。,此配置可以在服务器级别完成,因为“允许触发器”属性可以激活其他触发器。

0 个答案:

没有答案