[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pgsql-performance
Subject:    [PERFORM] trigger Before or After
From:       avpro avpro <avprowebeden () gmail ! com>
Date:       2014-11-11 6:38:11
Message-ID: CAAQdDnnb9E89=RxZbu6Fdv1eLtM7bQG9CLAsmYWxKZarnzXRQg () mail ! gmail ! com
[Download RAW message or body]

hi,

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

for example:

tables: actuals (summarize the total running hours), log (the functional
hours are inserted in LOG as time)
 function: sum
view: timeview (where running hours are calculated as a difference)

-- Function: sum()

-- DROP FUNCTION sum();

CREATE OR REPLACE FUNCTION sum()
 RETURNS trigger AS
$BODY$begin
update actuals
set
hours = hours + (select time from time_view
where idlog = (select max(idlog) from timeview))
where actuals.idmac =
(SELECT idmac FROM selectedmac) ;
return new;
end$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sum()
  OWNER TO user;




--trigger
CREATE TRIGGER update_actuals_tg01
  AFTER INSERT
  ON log
  FOR EACH ROW
  EXECUTE PROCEDURE sum();


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?

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

thank you
have a sunny day

[Attachment #3 (text/html)]

<div dir="ltr"><div><div><div><div><div>hi,<br><br></div>in the pgsql \
documentation<br>(<a \
href="http://www.postgresql.org/docs/9.1/static/sql-createtrigger.html">http://www.postgresql.org/docs/9.1/static/sql-createtrigger.html</a>)<br><br></div>i \
haven&#39;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<br></div><br>for example:<br><br></div>tables: actuals \
(summarize the total running hours), log (the functional hours are inserted in LOG as \
time)<br>  function: sum<br></div><div>view: timeview (where running hours are \
calculated as a difference)<br></div><div><span itemprop="text"><pre class="" \
style="height:264px">-- Function: sum()

-- DROP FUNCTION sum();

CREATE OR REPLACE FUNCTION sum()
 RETURNS trigger AS
$BODY$begin
update actuals
set 
hours = hours + (select time from time_view 
where idlog = (select max(idlog) from timeview))<br>where actuals.idmac = <br>(SELECT \
idmac FROM selectedmac) ; return new;
end$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sum()
  OWNER TO user;</pre></span><br><br></div><div><div><br>--trigger<br></div><div>CREATE \
TRIGGER update_actuals_tg01<br>   AFTER INSERT<br>   ON log<br>   FOR EACH ROW<br>   \
EXECUTE PROCEDURE sum();<br><br><br></div><div>I read somewhere (I don&#39;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?<br></div><div><br></div><div>what&#39;s the difference related to \
performance concerning a trigger Before Insert compared with a trigger After \
Insert?<br><br></div><div>thank you<br></div><div>have a sunny \
day<br></div><div><br></div></div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic