Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Hackers > why copy tuple ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 9507 of 10966
Post > Topic >>

why copy tuple in the end of trigger when nothing changed in NEW OLD record variable

by billywq@[EMAIL PROTECTED] ("billy") Jun 11, 2008 at 11:21 AM

Hi pghackers:

	version 8.3.0 in function plpgsql_exec_trigger.

	in a trigger, if NEW is returned as the result and we do nothing to NEW.


    for example, we have a table like this:

	create table test (a int);
    insert into test values(1);

	and a trigger like:

	create or replace function test_trigger() returns trigger as $$
    begin
        return new;
	end; $$language plpgsql;

    create trigger before_update_test before update
    on test for each row execute procedure test_trigger();


    in this trigger, we don't change the value of NEW.

	than execute:

    update test set a =3D 3;



	after execution:

   /* Copy tuple to upper executor memory */
   rettup =3D SPI_copytuple((HeapTuple) (estate.retval));

	we come to function ExecUpdate():

    HeapTuple newtuple;
    newtuple =3D ExecBRUpdateTriggers(estate, resultRelInfo,
          tupleid, tuple);



	Since the trigger's return value is copied to another memory address, the
=
newtuple is impossible equal to the oldtuple.

	so the following condition:

	  if (newtuple !=3D tuple) /* modified by Trigger(s) */
	  {

 	is FALSE for ever.



    I think we can add some judgment conditions in function
plpgsql_exec_tr=
igger() to avoid this problem.


=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1billy
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1billywq@[EMAIL PROTECTED]
 via pgsql-hackers mailing list (pgsql-hackers@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
 




 2 Posts in Topic:
why copy tuple in the end of trigger when nothing changed in NEW
billywq@[EMAIL PROTECTED]  2008-06-11 11:21:31 
Re: why copy tuple in the end of trigger when nothing changed in
tgl@[EMAIL PROTECTED] (T  2008-06-10 23:43:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 13:38:58 CST 2008.