MYSQL禁用自动修剪

时间:2013-02-05 08:49:03

标签: mysql string trim

如果我输入两个只有空格的字符串。我将收到此错误消息:

  

ERROR 1062:为'PRIMARY'重复输入''

如何关闭“自动修剪”?

我正在使用此 Charset: uft8-uft8_bin 和此数据类型:Varchar

1 个答案:

答案 0 :(得分:7)

根据SQL 92文档,当比较两个字符串时,首先通过用空格填充最短字符串使它们的长度相等。

在文档中搜索8.2 <comparison predicate>

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>.

换句话说。它不是关于存储您输入的空格量的值,而是它与检查重复主键的比较。因此,您不能将两个具有不同空格量的字符串作为主键