Skip site navigation (1) Skip section navigation (2)

Re: Trigger to identify which column(s) updated

From: "Vishal Kashyap (at) [Sai Hertz And Control Systems]" <sank89(at)sancharnet(dot)in>
To: Jack Kerkhof <jack(dot)kerkhof(at)guest-tek(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Trigger to identify which column(s) updated
Date: 2004-01-18 22:29:00
Message-ID: 400B08AC.8040607@sancharnet.in (view raw or flat)
Thread:
Lists: pgsql-sql
Dear Jack ,

>I suspect that the function would look something like;
>
>CREATE FUNCTION FIND_CHANGED_COLUMNS() RETURNS OPAQUE AS '
>BEGIN
>
>   -- FOR EACH COLUMN IN THE RECORD:
>      -- IF ( NEW COLUMNx <> OLD COLUMNx)
>         -- LOG THE RECORD PRIMARY KEY, COLUMN NAME, OLD VALUE
>
>   RETURN NEW;
>END;
>' LANGUAGE 'plpgsql';
>  
>

Instead of using a trigger use a rule as
<code>


</code>
CREATE RULE log_allthat  AS ON UPDATE TO table_to_scan  WHERE 
((NEW.coloum_1 !=  old.NEW.coloum_1) OR (NEW.coloum_2 !=  
old.NEW.coloum_2)) OR (MORE COLUMNS DO

 INSERT INTO log_changes_table (

PRIMARY_KEY,COLUMN_NAME,OLD_VALUE

) VALUES (

OLD.PRIMARY_KEY,OLD.COLUMN_NAME,OLD.OLD_VALUE

);


Yes you will have to create a table as log_changes_table or any name you 
fancy such that data could be loged
</code>

Kindly shoot back if this helps.

-- 
Regards,
Vishal Kashyap

~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
I Know you believe my words so logon to Jabber.org
and add vishalkashyap(at)jabber(dot)org to your roster.
~*~*~*~*~*~*~*~*
I am usually called by the name Vishal Kashyap
but my Girl friend believes my name should be
Vishal CASH UP.This is because others love my
nature and my Girl friend loves my CASH.
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*


In response to

pgsql-sql by date

Next:From: Paul HartDate: 2004-01-19 02:58:38
Subject: Execute permissions for stored functions
Previous:From: Richard PooleDate: 2004-01-18 21:57:14
Subject: Re: Left joins with multiple tables

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group