Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Blocker
-
Resolution: Not a Bug
-
Affects Version/s: 5.5.33a-galera
-
Fix Version/s: None
-
Component/s: None
-
Labels:
-
Environment:Linux Debian Wheezy x64 - OVH dedicated server
Description
Create this table :
CREATE TABLE `user_session` (
`php_id` varchar(26) NOT NULL,
`session_id` varchar(32) NOT NULL DEFAULT '',
`session_data` text,
`session_time` int(11) NOT NULL,
PRIMARY KEY (`php_id`,`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Add any values and try to update them :
UPDATE user_session SET session_id = :session_id, session_data = :session_data, session_time = :session_time WHERE php_id = :php_id
i get always this error :
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'xxxx' for key 'PRIMARY'
This is illogical, i try to update an existing line, i should not have this error.
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Hi,
What do :session_id, etc signify? Where do you execute the statement from?
Could you please provide an example with real data, e.g. what you have in the table and what you are trying to update it to?
In general, there is nothing strange about this error. Lets say you have this data in the table:
MariaDB [test]> select * from user_session;
-------
-----------------------------------+-------
-----------------------------------+-------
-----------------------------------+2 rows in set (0.00 sec)
Then the following update will indeed cause the error:
MariaDB [test]> update user_session set session_id = 'a' where php_id = 'a';
ERROR 1062 (23000): Duplicate entry 'a-a' for key 'PRIMARY'
This is because you are updating several (two) rows at once, trying to modify them the way that their primary key becomes identical.
But of course, it all depends on the data in the table and in the query.