问题
I want to create an alias for the IF function in H2 for MySQL compatibility as asked here. Vituels answer explains how to do this with CREATE ALIAS:
CREATE ALIAS IF NOT EXISTS `IF` AS $$
String ifFunction(boolean condition, String exp1, String exp2){
if(condition) {
return exp1;
} else {
return exp2;
}
}
$$;
This works if you use the alias with string parameters, but does not work for numbers. If I use Integer in the alias definition instead of String, it's the other way round. Using Object does not work with either type.
Is there a way to write the ifFunction so that it works for arbitrary data types?
This answer to a similar question states that it is possible to bind multiple methods to an alias if they have different number of arguments. This will not work for me because I need the same number of arguments, but for multiple data types.
来源:https://stackoverflow.com/questions/37595970/create-alias-which-works-for-strings-and-numbers-in-h2