PostgreSQL에서 테이블의 UPDATE / INSERT시 트리거가 발생하는 경우,
트리거 함수내에서 같은 테이블의 UPDATE / INSERT문이 실행되면
재귀문제가 발생하여 스택오버플로우(stack overflow) 문제가 발생한다.
재귀가 발생하는 문제를 해결하기 위해서는
트리거에 pg_trigger_depth() = 0을 추가한다.
CREATE TRIGGER trg_taxonomic_positions
AFTER INSERT OR UPDATE OF taxonomic_position
ON taxon_concepts
FOR EACH ROW
WHEN (pg_trigger_depth() = 0)
EXECUTE PROCEDURE trg_taxonomic_positions()
stack overflow를 참고해서 해결하였기에 더 구체적인 내용은 이하의 내용을 참고.
https://stackoverflow.com/questions/708562/prevent-recursive-trigger-in-postgresql
Prevent recursive trigger in PostgreSQL
How to prevent recursive execution of trigger? Let's say I want to construct a "tree-able" description on chart of account. So what I do is when a new record is inserted/updated, I update the the ...
stackoverflow.com
Is pg_trigger_depth() bad to use for preventing trigger cascading (recursion)?
Why is pg_trigger_depth() = 0 bad to use (for anything other than debugging) when preventing trigger cascading (recursion)? Can someone provide code to demonstrate why it is bad? I am guessing b...
dba.stackexchange.com
'IT 스터디 > 포스트그레스큐엘(postgresql)' 카테고리의 다른 글
PostgreSQL 트리거 함수 변수값 초기화, 대입하는 방법 (0) | 2022.11.05 |
---|