Duplicate entry for key 'PRIMARY' .Ignoring the spaces for strings

后端 未结 2 646
情书的邮戳
情书的邮戳 2021-01-07 13:11
mysql> CREATE TABLE primary2(boom text,id int,PRIMARY KEY(boom(5)) );
Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO primary2 VALUES(\'viok\',1);
Que         


        
2条回答
  •  感情败类
    2021-01-07 13:36

    Q: How to add a string with spaces?

    A: It's not possible.

    The TEXT values 'viok' and 'viok ' are not unique, in terms of how MySQL stores those as index entries. This is documented behavior:

    If a TEXT column is indexed, index entry comparisons are space-padded at the end. This means that, if the index requires unique values, duplicate-key errors will occur for values that differ only in the number of trailing spaces. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error. This is not true for BLOB columns.

提交回复
热议问题