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
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.
I've just had the same issue, and I resolved it with CASE/WHEN/THEN
SQL statement. So you can rewrite your query as follows:
SELECT CASE WHEN true THEN 'TRUE!!' ELSE 'FALSE!!!' END;
Surely it's more verbose, but it fits both H2 and MySQL.
Yes you can create the if function as an alias:
CREATE ALIAS IF NOT EXISTS `IF` AS $$
String ifFunction(boolean condition, String exp1, String exp2){
if(condition) {
return exp1;
} else {
return exp2;
}
}
$$;