Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id CFCDD4766DA; Thu, 22 Aug 2002 02:10:29 -0400 (EDT) Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net [194.217.242.91]) by postgresql.org (Postfix) with ESMTP id 150D04766D6; Thu, 22 Aug 2002 02:10:29 -0400 (EDT) Received: from lfix.demon.co.uk ([158.152.59.127] helo=linda.lfix.co.uk) by anchor-post-33.mail.demon.net with esmtp (Exim 3.35 #1) id 17hlAq-0003ST-0X; Thu, 22 Aug 2002 07:10:28 +0100 Received: from localhost ([127.0.0.1] helo=localhost.localdomain ident=olly) by linda.lfix.co.uk with esmtp (Exim 3.35 #1 (Debian)) id 17hlAp-0000ha-00; Thu, 22 Aug 2002 07:10:27 +0100 Subject: Re: [ADMIN] How to execute my trigger when update certain columns From: Oliver Elphick To: Raymond Chui Cc: pgsql-sql@postgresql.org, pgadmin-support@postgresql.org, pgsql-general@postgresql.org, pgsql-admin@postgresql.org In-Reply-To: <3D5A487F.ECFECBAE@noaa.gov> References: <3D5A487F.ECFECBAE@noaa.gov> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 22 Aug 2002 07:10:27 +0100 Message-Id: <1029996627.31594.1742.camel@linda> Mime-Version: 1.0 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/98 X-Sequence-Number: 722 On Wed, 2002-08-14 at 13:09, Raymond Chui wrote: > Let say I have a table has column1 and column2 and I made a trigger for > after INSERT OR UPDATE for each row to execute procedure my_function. > > What I want is the trigger execute my_function only when column1 is > insert or > update, but not going to execute my_function when column2 is insert or > update. The trigger is executed unconditionally, so put the condition inside my_function. If it's an INSERT, column1 must be new, so: IF TG_OP = ''INSERT'' OR (TG_OP = ''UPDATE'' AND (NEW.column1 != OLD.column1 OR (NEW.column1 IS NULL AND OLD.column1 IS NOT NULL) OR (NEW.column1 IS NOT NULL AND OLD.column1 IS NULL) ) ) THEN ... END IF; -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight, UK http://www.lfix.co.uk/oliver GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C ======================================== "For yourselves know perfectly that the day of the Lord so cometh as a thief in the night. For when they shall say, Peace and safety; then sudden destruction cometh upon them, as travail upon a woman with child; and they shall not escape." I Thessalonians 5:2,3