2

The issue: Query concat on date column turns search case sensitive. When date column removed from concat the search is not case sensitive and returns the expected result set. This is happening in DEV but not QA environment.

Both environments have the same Server, Database and Connection collation settings, latin1_swedish_ci, but are different Mysql versions (DEV:5.1.39; QA:5.1.61).

The table attributes in each environment (engine, charset) are the same: InnoDB and latin1.

QRY:

 select contact_id, lastname, firstname, dob
 from contact
 where concat(lastname,' ',firstname,' ',dob) = 'styles furious 1988-06-18';

We need the query to be case insensitive.

Any help is appreciated, thanks.

4

2 回答 2

1

CONCAT()无论如何,当您可以在客户端拆分字符串并执行操作时,您为什么还要使用?

select contact_id, lastname, firstname, dob
from contact
where lastname = 'styles' and firstname = 'furious' and dob = '1988-06-18'

只要lastnamefirstname列都是非二进制的并且使用不区分大小写的排序规则,则此查询应该不区分大小写。如果您在这些列上有索引,它也应该更有效率。

无论如何,如果您绝对坚持使用CONCAT(),您始终可以强制结果具有正确的类型和排序规则,如下所示

select contact_id, lastname, firstname, dob
from contact
where
  convert(concat(lastname, ' ', firstname, ' ', dob) using latin1)
    collate latin1_general_ci = 'styles furious 1988-06-18';

但是,这确实很丑陋且效率低下,除非您真的没有其他选择,否则您甚至不应该考虑在生产中使用它。

于 2013-01-03T00:02:04.457 回答
0

您是否尝试过在 concat 和字符串周围使用 upper 函数,以便比较两者的大写版本?

据我所知,= 总是区分大小写的(我自己对 mysql 很陌生,所以不是 100%,但我希望是这样)。环境之间是否可能存在其他一些差异(表中传递的数据或查询中要比较的值)会导致它返回一行?

于 2013-01-02T23:56:32.230 回答