Отключение каскадного выполнения триггеров

Здравствуйте!
Я выполняю следующую команду:
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;

По тексту триггерной функции видно, что при её выполнении будет осуществляться Insert в таблицу CSM_ATTR (триггер TriggerFunctionCsmAttrIns) и Insert в таблицу CSM_ATTR_LOG (триггер TriggerFunctionCsmAttrIns).

Вопрос: Можно как то настроить PostgreSql, что бы не было каскадного срабатывания триггеров из другого триггера?
P.S. в MS SQL Server такую настройку можно сделать на уровне сервере, как свойство Разрешить триггерам активизировать другие триггеры.

USE AdventureWorks2012 ;  
GO  
EXEC sp_configure 'show advanced options', 1;  
GO  
RECONFIGURE ;  
GO  
EXEC sp_configure 'nested triggers', 0 ;  
GO  
RECONFIGURE;  
GO

Back to top

(С) Виктор Вислобоков, 2008-2010