I need to track data changes in DB and execute a trigger. The base records have a few associated (many-to-one) records in different tables. When any of the records (base or associated) are updated/inserted, the trigger has to be executed to perform some operations based on the base record and all associated records data.
When a new base record and all its associated records are inserted (created new records), is there any way to prevent the trigger from executing each time an associated record is inserted? I mean, is there a way to wait until all related data is stored and then run the trigger?
I can't guarantee that all insertions are performed in a single transaction and can't change the way the records are inserted. All I can do is add triggers and functions to existing DB.
I know that this question sounds naive and silly, but any crazy idea would be appreciated.