H2 内存数据库在 MySQL 模式下以不同方式对待 ORDER BY
我有一个查询,它对包含电子邮件地址的 VARCHAR 列执行ORDER BY
。
如果我访问物理 MySQL 数据库,它会忽略 ORDER BY 中的大小写。但是,我的 h2 内存数据库尊重大小写。它被设置为 MySQL 模式。
有谁知道这是为什么吗?
I have a query that does anORDER BY
on a VARCHAR column that contains email addresses.
If I hit my physical MySQL db, it ignores case in the ORDER BY
. However, my h2 in-memory DB is respecting case. It is set to MySQL mode.
Anyone know why this is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
评估数据库中的字符串时区分大小写是由排序规则决定的。
检查 H2 上的排序规则处理: http://www.h2database.com/html/grammar .html#set_collation
Case sensitivity when evaluating strings in databases is determined by the collation.
Check the collation handling on H2: http://www.h2database.com/html/grammar.html#set_collation
作为使用排序规则的替代方法,您可以使用 SET IGNORECASE TRUE 禁用区分大小写。这需要在创建表之前完成。
H2 的 MySQL 模式不不区分大小写的原因是:H2 中的兼容模式不会影响事物的持久化方式(否则稍后您将无法以不同的兼容模式访问数据库) ,或禁用兼容模式)。区分大小写确实会影响事物的存储方式(特别是索引)。
As an alternative to using a collation, you can disable case sensitivity using SET IGNORECASE TRUE. This needs to be done before creating the tables.
The reason why the MySQL mode of H2 isn't case insensitive is: compatibility modes in H2 don't affect how things are persisted (otherwise you couldn't access a database in a different compatibility mode later on, or disable the compatibility mode). Case sensitivity does affect how things are stored (specially indexes).
使用
VARCHAR_IGNORECASE
而不是VARCHAR
。参考
Use
VARCHAR_IGNORECASE
instead ofVARCHAR
.Reference