I have a bunch of updates I am doing to a bunch of tables, some tables already have the updates completed so when I try to run the update statement it's throwing an error. The error is good so know I don't have to perform the update.
So my question is, since the updates have already been completed, I don't mind that the sql inserts have failed and I can skip them.
With that being said, is it bad practice to add a try catch and just do nothing in the except block and commit the transactions when the failed update occurs or is there a better/cleaner way to do it? Thanks!
The most efficient method is to have the DB intelligently throw the duplicate in the bit bucket on the floor without troubling the caller. I recommend using the ON CONFLICT
clause in PostgreSQL.
I'm using mssql, I'll check and see if they have an on conflict. Thanks!
It didn't last I checked. It has a similar MERGE statement, IIRC, but it isn't deterministic in busy tables.
(It really helps to have a competent database.)
2 Likes
Tell that to the company I work for! haha thanks again
I was just reading up on merge
Watch out for side effects in other DBs that make the alternatives not truly equivalent to the SQL Standard's ON CONFLICT.