MYSQL禁用自动修剪 [英] MYSQL disable Auto-Trim

查看:50
本文介绍了MYSQL禁用自动修剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

错误1062:键"PRIMARY"的条目"重复

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

如何关闭自动修剪"?

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

推荐答案

根据

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.

在文档中搜索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>.

换句话说.它不是要与输入的空格数量一起存储值,而是要检查是否有重复的主键.因此,不能有两个空格不同的字符串充当主键

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

这篇关于MYSQL禁用自动修剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆