Re: recursive trigger - Mailing list pgsql-general

From Tom Lane
Subject Re: recursive trigger
Date
Msg-id 4041.1078681276@sss.pgh.pa.us
Whole thread Raw
In response to recursive trigger  (Mage <mage@mage.hu>)
Responses Re: recursive trigger
List pgsql-general
Mage <mage@mage.hu> writes:
> what's wrong with this?

>  if new.parent <> old.parent then
>    update test set name = ''old'' where parent = old.parent;

You should just do

 if new.parent <> old.parent then
   new.name = ''old'';

As you have it, the inner UPDATE pre-empts the outer because it is
applied first.  When control comes back from the trigger, the row
the trigger was handed is now dead (already updated) and can't be
updated again.

            regards, tom lane

pgsql-general by date:

Previous
From: Michael Meskes
Date:
Subject: Re: ECPG - bug in EXEC SQL WHENEVER NOT FOUND?
Next
From: Mage
Date:
Subject: Re: recursive trigger