发现多种数据库 group by 对字符串首尾空格的坑死人不偿命规范
rt 已测试 mysql sqlserver
“字符串” “字符串 ” 会分到同一组
“字符串” ” 字符串” 又不会分到同一组
这种默认操作站在字符数据存储的角度,和默认不区分大小写一样愚蠢至极,本人观点。
rt 已测试 mysql sqlserver
“字符串” “字符串 ” 会分到同一组
“字符串” ” 字符串” 又不会分到同一组
这种默认操作站在字符数据存储的角度,和默认不区分大小写一样愚蠢至极,本人观点。
u00a0==’ ‘ mysql✅,sqlserver❌
u2000==’ ‘ mysql✅,sqlserver❌
u3000==’ ‘ mysql✅,sqlserver✅
字符串首尾空格,似乎还影响到了 len 、length 、=、!= 、in,太可怕,这种功能却不是另外开一个明确表意的函数来做,黑暗、可怕
js 可以 trim 掉常见但又敲不出的空格,如我 2 这 3 个
java 只能 trim 掉 u0020 键盘敲出来的这个空格,其他空格 trim 不掉
其他语言没测试 trim,反正总有个地方会让你跳进去
网页内搜索 SQL standard
This somewhat bizarre exception is required by the SQL standard
通常都用 VARCHAR 的,没这个问题
或者上 PostgreSQL 全用 TEXT 完事。
The only exception to this rule is the LIKE predicate. When the right side of a LIKE predicate expression features a value with a trailing space, SQL Server does not pad the two values to the same length before the comparison occurs. Because the purpose of the LIKE predicate, by definition, is to facilitate pattern searches rather than simple string equality tests, this does not violate the section of the ANSI SQL-92 specification mentioned earlier.