Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8943363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:45:06+00:00 2026-06-15T11:45:06+00:00

I want to insert a row, but if a conflict occurs (example below) I’d

  • 0

I want to insert a row, but if a conflict occurs (example below) I’d like the database to lock the existing row so I can log its contents for debugging purposes. I am using READ_COMMITTED transaction isolation.

For example:

CREATE TABLE users(id BIGINT AUTO_INCREMENT, name VARCHAR(30),
  count INT NOT NULL, PRIMARY KEY(id), UNIQUE(name));

Thread 1:
  INSERT INTO users(username, count) VALUES('joe', 1000);
  transaction.commit();

Thread 2:
  // Insert fails due to conflict with above record
  INSERT INTO users(username, count) VALUES('joe', 0);

  // Get the conflicting row and log its properties
  SELECT * FROM users WHERE username = 'joe';

If the conflicting row is not locked, it may be modified by the time I check it. The only workaround I found is invoking SELECT id FROM users WHERE username = 'joe' FOR UPDATE before the insert. Is it possible way to implement this without any overhead when a conflict does not occur?

UPDATE: I am not asking to avoid the conflict or the resulting SQLException. I am just asking for the conflicting row to get locked so I can look up what values triggered the conflict. Yes, I know that the conflicting record contains joe but I want to log all its other columns.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:45:07+00:00Added an answer on June 15, 2026 at 11:45 am

    There doesn’t seem to be a portable way of doing this and looking at MVCC there is a strong indication that this cannot be implemented without a substantial performance impact.

    So in conclusion: you’re going to have to settle for knowing that a conflict occurred but have no way of being 100% sure of the cause (there is no thread-safe to verify).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want insert following checkbox in a row from database table, but have error,
I want to insert a row into the Database using SqlDataAdapter. I've 2 tables
I have created database table. But there is a strange thing I can insert
In my SQLite database only one row effect but I want effect 4 rows
I have defined a DefaultTableModel and I want to insert a new Row, but
I want to insert a row number in a records like counting rows in
I want insert in the row from database, array of values as that each
I want to insert multiple values into a row, but I want to make
I want to insert row for each day to add new values, and I
I want to insert a row in a table, and when I do the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.