MYSQL disable Auto-Trim

前端 未结 1 1926
广开言路
广开言路 2021-01-18 08:29

If I enter two Strings with only white space. I will Get this error message:

ERROR 1062: Duplicate entry \' \' for key \'PRIMARY\'

相关标签:
1条回答
  • 2021-01-18 08:49

    According to the SQL 92 documentation, when two strings are compared they are first made equal in length by padding the shortest string with spaces.

    Search for 8.2 <comparison predicate> in the document.

    If the length in characters of X is not equal to the length
    in characters of Y, then the shorter string is effectively
    replaced, for the purposes of comparison, with a copy of
    itself that has been extended to the length of the longer
    string by concatenation on the right of one or more pad char-
    acters, where the pad character is chosen based on CS. If
    CS has the NO PAD attribute, then the pad character is an
    implementation-dependent character different from any char-
    acter in the character set of X and Y that collates less
    than any string under CS. Otherwise, the pad character is a
    <space>.
    

    So in other words. Its not about storing the value with the amount of spaces you entered, but its the comparisment it does to check for duplicate primary key. So you cannot have two strings with a different amount of spaces act as a primary key

    0 讨论(0)
提交回复
热议问题