Search Postgresql Archives

Re: [PERFORM] trigger Before or After

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



avpro avpro wrote:
> in the pgsql documentation
> (http://www.postgresql.org/docs/9.1/static/sql-createtrigger.html)
> 
> 
> i haven't seen anything referring to: how is affected the data inserted in the new table by a trigger
> Before Insert compared with a trigger After Insert? and anything related to performance

In your example (the trigger updates a second table) it should make
no difference if the trigger is BEFORE or AFTER INSERT.

The difference is that in a BEFORE trigger you can modify the values that
will be inserted before the INSERT actually happens.

> I read somewhere (I don't find the link anymore) that if the trigger is After Insert, the data
> available in the table LOG might not be available anymore to run the trigger. is that correct? or I
> might understood wrong?

I don't quite understand.
You will have access to the OLD and NEW values in both BEFORE and AFTER triggers.
In an AFTER trigger, the table row has already been modified.

> what's the difference related to performance concerning a trigger Before Insert compared with a
> trigger After Insert?

I don't think that there is a big difference, but you can easily test it:
Insert 100000 rows with a BEFORE trigger on the table and compare the
time it takes to inserting 100000 rows with an AFTER trigger.

Yours,
Laurenz Albe

-- 
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux