jr76 wrote:
Thanks awerder for that suggestion. Doing the select after attempting the save/update avoids the race condition and is also more efficient.
Hi,
This will not work. Let me explain. Performing query before of after update/insert doesn't change the fact that this query does not see changes done in other transactions until those are commited. This presents a conceptual obstacle to all workarounds that are implemented on an application level. In a concurrent environment it is likely that there will be two transactions saving same value and querying for duplicates at the same or near same time and getting validation done before they both commit. This will warrant that the same value is inserted twice or one of the sessions will get unique constraint violation if there is a DB unique constraint. The only workaround is to lock tables for concurrent modifications for entire period from validating to committing.
Your thoughts are appreciated.
Best regards,
- Vlad