MYSQL disable Auto-Trim

房东的猫 提交于 2019-11-30 09:14:49

问题


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

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

How can I Turn off "Auto-Trim" ?

I'm Using this Charset: uft8-uft8_bin and This Datatype: Varchar.


回答1:


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



来源:https://stackoverflow.com/questions/14703349/mysql-disable-auto-trim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!