Create alias which works for strings and numbers in H2

◇◆丶佛笑我妖孽 提交于 2019-12-22 10:06:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!