Adrian Klaver <adrian.klaver@gmail.com> wrote:
> On 06/01/2013 06:47 AM, Kevin Grittner wrote:
>> Currently on an AFTER ... FOR EACH ROW we fire the trigger once
>> *for* each affected row, that's true. But we don't do it
>> immediately after the *triggering event* -- we do it immediately
>> after the *data change statement*. The issue isn't how many times
>> we execute the trigger, or with what parameters, but *when* it
>> runs.
>
> Aah, that was the part I was missing. So to see if I understand, in the
> OPs case:
>
> 1) The first case worked as Juliano expected because the INSERTs where
> done in a loop where each INSERT was a discrete statement and there was
> a 1:1 correspondence between statement and triggering event.
>
> 2) The second case did not work as expected because the INSERTs where
> wrapped up in a single statement and the AFTER triggers ran for each row
> after all the rows where inserted not after each row was inserted.
Exactly.
--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company