Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IF function in H2 for MySQL compatibility

Tags:

mysql

h2

I'm using H2 (with MySQL compatibility mode) to write some automated tests against our software that uses MySQL. Unfortunately, it seems like H2 does not have have the IF function that many of our queries use. Short of rewriting our application queries with something like DECODE, is their a good way to create the if function, say as an Alias?

The error that I'm getting:

WARNING: Failed to execute: SELECT IF(true,'TRUE!!','FALSE!!!') because: Function "IF" not found; SQL statement:
like image 839
vicsz Avatar asked Dec 15 '14 22:12

vicsz


1 Answers

Ended up just rewriting queries to use functions compatible with both database - H2, MySql. In my case, the functions in question were replaced with IFNULL.

like image 81
vicsz Avatar answered Sep 28 '22 11:09

vicsz