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?
pvsbandiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

earth man2Commented:
declare
  add_audit_record boolean;
begin
if OLD.end_dt <> NEW.end_dt then
   -- check if nothing else has changed then don't add audit record;
   add_audit_record := OLD.col1 <> NEW.col1 or OLD.col2 <> NEW.col2;  --etc
  if  add_audit_record then
       -- add audit record
  end if;
else
  -- add audit record
end if;

  return NEW;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pvsbandiAuthor Commented:
Thank you
0
earth man2Commented:
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
0
pvsbandiAuthor Commented:
Oh thank you! I wrapped both the sides with a coalesce to deal with the nulls.
0
pvsbandiAuthor Commented:
Hi,

   Using your logic, how can we compare fields using an update trigger and use the same for insert or delete?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PostgreSQL

From novice to tech pro — start learning today.