gpt4 book ai didi

mysql varbinary 与 varchar

转载 作者:行者123 更新时间:2023-11-30 23:03:40 27 4
gpt4 key购买 nike

我们使用 varchar(255) 在 mysql 中存储“关键字”。我们面临一个问题,即 mysql 会忽略“=”中用于比较目的的所有尾随空格。它确实尊重“like”比较中的尾随空格,但它不允许我们在 varchar 列中存储带有和不带有尾随空格的相同单词(如果它上面有“UNIQUE”索引)。

因此,我们正在考虑改用 varbinary。当列值中有多字节字符时,有人能提出建议吗?

最佳答案

安多马尔

我们使用 5.0.5 版。所有 mysql 版本都忽略尾随空格进行比较。来自手册:

All MySQL collations are of type PADSPACE. This means that all CHAR and VARCHAR values in MySQL are compared without regard to any trailing spaces. This is true for all MySQL versions, and it makes no difference whether your version trims trailing spaces from VARCHAR values before storing them

此外,mysql 认为在索引中有/没有尾随空格的文本是重复的:

For those cases where trailing pad characters are stripped or comparisons ignore them, if a column has an index that requires unique values, inserting into the column values that differ only in number of trailing pad characters will result in a duplicate-key error. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error.

而且,我们绝对需要关键字索引。所以,我想我们有两个选择:varbinary 或 text。我们将评估“文本”的性能和 varbinary 的多字节功能。

关于mysql varbinary 与 varchar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22786418/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com