I am trying to create an alias in H2database for IF
and I get the following error.
org.h2.jdbc.JdbcSQLSyntaxErrorException: Function alias "IF" already exists; SQL statement:
CREATE ALIAS `IF` FOR "test.Udf.ifAlias" [90076-212]
Then I try to drop the IF
before creating, and I get the following error.
org.h2.jdbc.JdbcSQLSyntaxErrorException: Function alias "IF" not found; SQL statement:
DROP ALIAS `IF` [90077-212]
Similar happens for IFNULL
. I am trying the following lines in my init script.
DROP ALIAS `IF`;
CREATE ALIAS `IF` FOR "test.Udf.ifAlias";
And the Java function for the ifAlias
is
public static boolean ifAlias(boolean condition, boolean exp1, boolean exp2) {
if(condition) {
return exp1;
}
return exp2;
}
Since version 1.4.198, IF is a keyword in h2. See this issue and responses: https://github.com/h2database/h2database/issues/3018