Prevent recursive trigger in PostgreSQL

前端 未结 4 1226
礼貌的吻别
礼貌的吻别 2020-11-29 06:38

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

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 07:02

    In pg, it's up to you to track trigger recursion.

    If a trigger function executes SQL commands then these commands might fire triggers again. This is known as cascading triggers. There is no direct limitation on the number of cascade levels. It is possible for cascades to cause a recursive invocation of the same trigger; for example, an INSERT trigger might execute a command that inserts an additional row into the same table, causing the INSERT trigger to be fired again. It is the trigger programmer's responsibility to avoid infinite recursion in such scenarios.

    https://www.postgresql.org/docs/13/trigger-definition.html

提交回复
热议问题