X-Original-To: pgsql-sql@postgresql.org Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by postgresql.org (Postfix) with SMTP id 08762476313 for ; Fri, 7 Mar 2003 07:04:53 -0500 (EST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Fri Mar 07 13:04:54 2003 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id NAA22597; Fri, 7 Mar 2003 13:04:54 +0100 (MET) Message-ID: <3E688AE5.5714092D@rodos.fzk.de> Date: Fri, 07 Mar 2003 13:04:54 +0100 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Cc: Andreas.Pflug@web.de Subject: Re: How to notice column changes in trigger Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Archive-Number: 200303/185 X-Sequence-Number: 12225 > > How can I detect whether a column was changed by an update command > inside a trigger? > > create table test(a int, b int, c int, primary key(a)) > > b and c should be updated inside an update trigger if not modified by > the statement itself > > 1) update test set a=0 -> trigger does its work > 2) update test set a=0, b=1, c=2 -> trigger does nothing > 3) update test set a=0, b=b, c=c -> trigger does nothing, but content of > a and b dont change either although touched > > What I'm looking for is something like > IF NOT COLUMN_TOUCHED(b) THEN ... > For MSSQL, this would be coded as IF NOT UPDATE(b) .. > > IF OLD.b=NEW.b will not work, case 3) will falsely execute the trigger code. > Sorry, but I don't get it. Does > b and c should be updated inside an update trigger if not modified by > the statement itself mean b=b not modified, b=1 modified even if b was 1 before ? So you want the trigger executed only if assignments to b and/or c do not appear within the update command. Right? Regards, Christoph