pvsbandi
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
add_audit_record := OLD.col1 is distinct from NEW.col1 or OLD.col2 is distinct from NEW.col2; --etc
ASKER
Oh thank you! I wrapped both the sides with a coalesce to deal with the nulls.
ASKER
Hi,
Using your logic, how can we compare fields using an update trigger and use the same for insert or delete?
Using your logic, how can we compare fields using an update trigger and use the same for insert or delete?
ASKER