Link to home
Start Free TrialLog in
Avatar of pvsbandi
pvsbandiFlag for United States of America

asked on

Postgres no trigger action on a condition

Hi,
   We are on Postgres 9.6.
  I have a table called tbl_client. This has many fields and one of the fields is called end_dt.
My requirement is to insert a row into another table called tbl_audit, for any changes in tbl_client.
So, i created a trigger to capture the same.

Now, the requirement is that i don't insert a row if the change is only on the end_Dt.

Can someone give me an idea how this can be added to the condition?
ASKER CERTIFIED SOLUTION
Avatar of earth man2
earth man2
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pvsbandi

ASKER

Thank you
if you need to test for columns changing to/from NULL you could consider using
add_audit_record := OLD.col1 is distinct from NEW.col1 or OLD.col2 is distinct from NEW.col2;  --etc
Oh thank you! I wrapped both the sides with a coalesce to deal with the nulls.
Hi,

   Using your logic, how can we compare fields using an update trigger and use the same for insert or delete?