X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9C849D1B546 for ; Mon, 22 Sep 2003 05:19:04 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 50884-06 for ; Mon, 22 Sep 2003 02:18:33 -0300 (ADT) Received: from rock.spider.ru (rock.spider.ru [62.183.34.226]) by svr1.postgresql.org (Postfix) with ESMTP id 32303D1B95E for ; Mon, 22 Sep 2003 02:18:32 -0300 (ADT) Received: from rock (localhost [127.0.0.1]) by rock (Postfix) with SMTP id 43517912B7 for ; Mon, 22 Sep 2003 09:18:31 +0400 (MSD) Received: from sad.localnet.ru (sad.localnet.ru [10.0.0.33]) by rock.spider.ru (Postfix) with ESMTP id ECFC59122E for ; Mon, 22 Sep 2003 09:18:30 +0400 (MSD) Content-Type: text/plain; charset="iso-8859-1" From: sad Organization: IT To: pgsql-sql@postgresql.org Subject: Re: Reg: Firing Trigger when a particular column value get changed Date: Mon, 22 Sep 2003 09:21:56 +0400 User-Agent: KMail/1.4.3 References: <63970.192.168.64.193.1063969270.squirrel@mail2.siptech.co.in> <3F6CD6E9.5030005@houle.org> In-Reply-To: <3F6CD6E9.5030005@houle.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200309220921.56092.sad@bankir.ru> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/241 X-Sequence-Number: 15219 On Sunday 21 September 2003 02:38, you wrote: > Thilak babu wrote: > > I have a scnerio as to fire a trigger when i update a particular colu= mn > > in a table. Please do help me out in getting thro this. > > The trigger function can use logic to exclude cases where a particular > column does not change. For example: > > CREATE FUNCTION "column_update" () RETURNS TRIGGER AS ' > BEGIN > IF ( NEW.column <> OLD.column ) THEN > do-your-stuff-here; > END IF; > RETURN NEW; > END; ' LANGUAGE 'plpgsql'; this trigger will not execute "your-stuff-here" if NEW.column or OLD.column will be null. you need to add this case to the logic statement in the "IF" (NEW.column <> OLD.column) OR (NEW.column IS NULL <> OLD.column. IS NULL)