Created
March 2, 2023 11:15
-
-
Save shner-elmo/6a25e177aa6c26827eb556defb0aebd5 to your computer and use it in GitHub Desktop.
MySQL raises a `DUPLICATE KEY ERROR` from two different values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `test` ( | |
`title` varchar(255) PRIMARY KEY | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | |
INSERT INTO test (title) VALUES ('1. Līga'), ('1. liga'); -- raises: Error Code: 1062. Duplicate entry '1. liga' for key 'PRIMARY' | |
DROP TABLE `test`; | |
-- ############################################################ | |
CREATE TABLE `test` ( | |
`title` varchar(255) PRIMARY KEY | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_as_cs; | |
INSERT INTO test (title) VALUES ('1. Līga'), ('1. liga'); | |
SELECT * FROM test; -- after changing the COLLATE to case_sensitive everything works! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment