Postgres Exception in If-then-else

pvsbandi
pvsbandi used Ask the Experts™
on
Hi,

 I have a trigger where there is an insert, update and a delete, conditionally.
 I want to let the trigger do its work, but if there is any error, while doing any transactions, i would like to ignore it.
I tried inserting the exception when others, at the end of the function, but that is not ignoring the results.

Can someone kindly suggest how to add that exception logic in the attached sql.
fn_trg_attribute_audit.sql
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer

Commented:
I want to let the trigger do its work, but if there is any error, while doing any transactions, i would like to ignore it.
Why, on earth, would you like this?

This means, in a case of an transactional error, the trigger may not do its job, thus your audit trail is incorrect. This makes no sense to me.

Author

Commented:
The main culprit would be the unique constraint violation error.
I just want to bypass it and any other errors.
The intent of the trigger is not to capture the errors in the transaction, but to do the transaction itself.
It's fine in my case, to simply ignore any errors that might be encountered.
ste5anSenior Developer

Commented:
What unique constraint? This sounds like a sever data model issue. A audit table has no such constraints.

Author

Commented:
The primary key in the transaction table increments by a sequence.
There are some rare instances when two or more transactions happen at the exact same time causing the sequence to generate the same number, which violates the uniqueness of the primary key.

Ethical or not, I just need a way to ignore any errors raised because of the trigger.
Please advise

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial