pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Houle <kevin@houle.org>
To: Thilak babu <thilakbabu@siptech.co.in>
Subject: Re: Reg: Firing Trigger when a particular column value get changed
Date: Sat, 20 Sep 2003 18:38:33 -0400
Message-ID: <3F6CD6E9.5030005@houle.org> (raw)
In-Reply-To: <63970.192.168.64.193.1063969270.squirrel@mail2.siptech.co.in>
References: <63970.192.168.64.193.1063969270.squirrel@mail2.siptech.co.in>

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





view thread (3+ messages)  latest in thread

Message-ID: <3F6CD6E9.5030005@houle.org>
Permalink:  ../3F6CD6E9.5030005@houle.org/
Also on:    postgresql.org/message-id/3F6CD6E9.5030005@houle.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: kevin@houle.org, thilakbabu@siptech.co.in
  Subject: Re: Reg: Firing Trigger when a particular column value get changed
  In-Reply-To: <3F6CD6E9.5030005@houle.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox