PostgreSQL trigger execution order

Поиск
Список
Период
Сортировка
От Sebastian Ritter
Тема PostgreSQL trigger execution order
Дата
Msg-id 20100706093339.GA407@campbell-lange.net
обсуждение исходный текст
Ответы Re: PostgreSQL trigger execution order  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Список pgsql-general
Hi All,

I posted a few questions earlier last week about how triggers are
executed and wanted to expand on them, if possible.

I have a table with 4 AFTER INSERT triggers defined for a table.

For example purposes lets call them A,B,C,D.

I know that they will execute in alphabetical order as per the
PostgreSQL docs.

However, on occasion, trigger B will cause another insert in the same
table. This, in turn, causes all the AFTER INSERT triggers to run again
for the newly inserted row from the first invocation of trigger B.

I have all the appropriate stop condition in place to avoid a never
ending cycle of trigger invocations.

My question is the following:

In what order will the triggers be executed?

Will it be:

INSERT row
INVOKE TRIGGER A (First call)
INVOKE TRIGGER B (First call) -> INSERT row
                                 INVOKE TRIGGER A (Second call)
                                 INVOKE TRIGGER B (let say no new insert)
                                 INVOKE TRIGGER C (Second call)
                                 INVOKE TRIGGER D (Second call)
INVOKE TRIGGER C (First call)
INVOKE TRIGGER D (First call)

Or will it be:

INVOKE TRIGGER A (First call)
INVOKE TRIGGER B (First call) -> INSERT row and wait...
INVOKE TRIGGER C (First call)
INVOKE TRIGGER D (First call)

INVOKE TRIGGER A (Second call)
INVOKE TRIGGER B (let say no new insert)
INVOKE TRIGGER C (Second call)
INVOKE TRIGGER D (Second call)

My last set of questions confirmed that triggers aren't run
multi-threaded and hence cannot be run in parallel, so I'm assuming one
of the above scenarios must happen. After putting a bunch of RAISE
NOTICEs in my triggers it would appear as though the former scenario is
happening but I'm not 100% sure.

Any help would be much appreciated.

Kindest regards,
Sebastian

--
Sebastian Ritter
Software Manager
sebastian@campbell-lange.net

Campbell-Lange Workshop
www.campbell-lange.net
0207 6311 555
3 Tottenham Street London W1T 2AF
Registered in England No. 04551928


В списке pgsql-general по дате отправления:

Предыдущее
От: "A. Kretschmer"
Дата:
Сообщение: Re: psql \dp equivalent or similar query?
Следующее
От: "Davor J."
Дата:
Сообщение: Re: Extending postgres objects with attributes