Re: recursive trigger

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mage <mage(at)mage(dot)hu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: recursive trigger
Date: 2004-03-07 17:41:16
Message-ID: 4041.1078681276@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mage <mage(at)mage(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mage 2004-03-07 19:35:56 Re: recursive trigger
Previous Message Michael Meskes 2004-03-07 14:31:14 Re: ECPG - bug in EXEC SQL WHENEVER NOT FOUND?