Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 In memory DB treating ORDER BY differently in MySQL mode

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?

like image 320
stevebot Avatar asked Jul 01 '11 19:07

stevebot


People also ask

Can H2 be used as an in-memory database?

It can work as an in-memory database with a very satisfying performance result. H2 can be programmed to listen to a port, and it will expose the in-memory database to external applications for remotely accessing and browsing the database.

What is the difference between MySQL and H2?

All database engines behave a little bit different. Where possible, H2 supports the ANSI SQL standard, and tries to be compatible to other databases. There are still a few differences however: In MySQL text columns are case insensitive by default, while in H2 they are case sensitive. However H2 supports case insensitive columns as well.

Is it possible to use H2 as a persistent database?

With this configuration, the data is not lost even after spring boot restart and computer restart. You would find H2 being very rarely used in this way. If you are really interested in a persistent database, we recommend exploring MySQL, Oracle or some other relational database.

How to run H2 in SQL Server mode?

I figured out that H2 supports a mode option that H2 uses to emulate behaviour of specific database. To run H2 in SQL Server mode you can use following JDBC URL. If you are using Spring Boot then you can specify using the following property. As you can see we have specify mode as MSSQLServer. With this mode, H2 emulates following features:


2 Answers

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

like image 184
OMG Ponies Avatar answered Oct 13 '22 09:10

OMG Ponies


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).

like image 2
Thomas Mueller Avatar answered Oct 13 '22 09:10

Thomas Mueller