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 8257127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:05:41+00:00 2026-06-08T02:05:41+00:00

The MySQL documentation states that when using INSERT … ON DUPLICATE KEY UPDATE, the

  • 0

The MySQL documentation states that when using INSERT … ON DUPLICATE KEY UPDATE, the affected-rows value will be 1 when a record was inserted, 2 if an existing record was updated.

We’re getting an affected-rows value of 3 when a record is updated, although I’m only seeing this when the updates are performed via MySQL calls using Connector-J from Java; when I invoke the stored procedure from the MySQL Workbench, I get the expected result of 2 rows updated.

Does anyone have any idea what this might mean? Is this perhaps a Connector-J annomaly? I’d be inclined to just run with it, but without a reasonable explanation, I’m left with concerns for my data integrity (which is, after all, one of the reasons to check the affected-rows value).

MySQL server version: 5.1.57; Connector-J version: 5.1.7 (Java 1.6)

Additional details:
This is the table being modified:

CREATE TABLE `UserContactProperty` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `UserContactId` int(11) NOT NULL,
  `Property` varchar(45) NOT NULL,
  `Value` tinytext,
  `Date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `Contact-Property` (`UserContactId`,`Property`),
  KEY `FK_UserContact` (`UserContactId`),
  CONSTRAINT `FK_UserContact` FOREIGN KEY (`UserContactId`) REFERENCES `UserContact` (`id`) ON   DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=28685 DEFAULT CHARSET=latin1

The stored procedure performing the insert/update is as follows:

CREATE PROCEDURE `setUserContactProperty`(
    UID VARCHAR(50),
    CID INT,
    Prop VARCHAR(45),
    Val TINYTEXT
)
BEGIN
    INSERT INTO UserContactProperty ( UserContactId, Property, Value )
        VALUES ( CID, Prop, Val )
        ON DUPLICATE KEY UPDATE Value = Val, Date = CURRENT_TIMESTAMP;
END
  • 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-08T02:05:42+00:00Added an answer on June 8, 2026 at 2:05 am

    It seems as a bug. please check the following link:

    http://bugs.mysql.com/bug.php?id=46675

    As reported there, the bug is related to another bug where the generated key list is wrong and the count is wrong too. (the second bug originated from here http://slava-technical.blogspot.co.il/2011/05/mysql-on-duplicate-key-update-breaks.html)

    I think you need to find a workaround. probably by querying the database prior to inserting to see if the row with this key exists or not. or insert and catch duplicate key exception and then make the update in that case.

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

Sidebar

Related Questions

The documentation page for INSERT ... SELECT states that for INSERT ... SELECT to
I'm using MySQL API's function mysql_real_escape_string() Based on the documentation, it escapes the following
it states in jqgrid documentation that the code below should allow local sorting with
I am trying to use PDO's lastInsertId method, but the documentation states that for
The MySQL documentation implies that you can assign one or more of a table's
I couldn't find anything about this in MySQL documentation. SELECT accesion_id, definition FROM accesion_table
The MySQL 5.4 documentation, on Optimizing Queries with EXPLAIN , says this about these
I have read the documentation ( http://dev.mysql.com/doc/refman/5.1/en/partitioning.html ), but I would like, in your
Tornado provides a tornado.database wrapper to access MySQL database: www.tornadoweb.org/documentation/database.html But in documentation I
Mysql: Table_A ------------ id name 1 Name1 2 Name2 Table_B ------------ a_id type value

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.