Postgres Exception in If-then-else


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

ste5anSenior DeveloperCommented:
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.
pvsbandiAuthor 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 DeveloperCommented:
What unique constraint? This sounds like a sever data model issue. A audit table has no such constraints.
pvsbandiAuthor 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
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

From novice to tech pro — start learning today.