MYSQL禁用自动修剪

Sim*_*wig 6 mysql string trim

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

错误1062:密钥'PRIMARY'重复输入''

如何关闭"自动修剪"?

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

Hug*_*ing 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>.
Run Code Online (Sandbox Code Playgroud)

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

  • 幸运的是 MYSQL 不允许你改变它。在手册http://dev.mysql.com/doc/refman/5.5/en/char.html中,它说“所有MySQL排序规则都是PADSPACE类型”。这意味着 MySQL 中的所有 CHAR 和 VARCHAR 值都会进行比较,而不考虑任何尾随空格。 (3认同)
  • 谢谢您的回答。你能告诉我如何设置无垫吗? (2认同)