Search code examples
javajdbch2

H2 in Memory trims trailing blanks


I'm utilizing an in-memory H2 Database for automated tests of a legacy system.

jdbc:h2:mem:testdb;MODE=Oracle

CREATE TABLE MYTABLE (MYCOLUMN CHAR(1));
INSERT INTO MYTABLE VALUES(' ');
SELECT '*' || MYCOLUMN || '*' FROM MYTABLE;

This statement returns * * on the Oracle db, but returns ** on the H2 db.

This leads to errors when testing.

How can I disable the trimming of char columns?

I cannot change the legacy code. I cannot change the legacy statements. I cannot change the legacy column types.

The tables for testing are created automatically; I could change behavior on that side.


Solution

  • You're using an entirely outdated version of H2, all modern versions don't trim trailing spaces from CHARACTER (CHAR) values. You need to upgrade your version of H2 to 2.*.*.