Re: Reg: Firing Trigger when a particular column value get changed

From: Kevin Houle <kevin(at)houle(dot)org>
To: Thilak babu <thilakbabu(at)siptech(dot)co(dot)in>
Subject: Re: Reg: Firing Trigger when a particular column value get changed
Date: 2003-09-20 22:38:33
Message-ID: 3F6CD6E9.5030005@houle.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thilak babu wrote:
> I have a scnerio as to fire a trigger when i update a particular column
> 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';

CREATE TRIGGER "tg_column_update"
BEFORE UPDATE ON "table_name"
FOR EACH ROW EXECUTE PROCEDURE "column_update" ();

The trigger fires on every update, but the procedure doesn't do
anything unless the particular column changes. I don't think a
trigger can be defined to fire on anything more granular than a
table operation.

Kevin

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Kevin Houle 2003-09-20 22:55:34 Re: Unique Constraint Based on Date Range
Previous Message yogesh selukar 2003-09-20 17:05:12 Re: Simple concatenation in select query