java - create alias with the same name but not the same signature -


in order use h2 database in our junit tests instead of calling oracle, blocked on creating aliases on h2 emulate oracle compatibility :

  • i first declared alias to_char date char conversion : works fine

    create alias to_char $$ java.lang.string tochar(java.util.date date, string format) throws exception{ ... }$$;

  • then try declare alias to_char number char conversion : h2 doesn't accept : create alias to_char $$ java.lang.string tochar(java.lang.number value){ ... }$$;

it rejected following error message :

org.h2.jdbc.jdbcsqlexception: function alias "to_char" exists; sql statement: create alias to_char $$

java.lang.string tochar(java.lang.number value){ return java.lang.string .valueof(value); }$$

i tried declare 2 functions in 1 block, :

create alias to_char $$

java.lang.string tochar(int value){ ... }

java.lang.string tochar(java.util.date date, string format) throws exception{ ... } $$;

in case, there no errors, firest method declared taken in account.

so, there way declare 2 aliases having same name not same signature ?

as to_char, h2 support now, since version 1.3.175 (2013-01-18).

h2 support function overloading. however, there limitation, because declaring such functions source code not supported.

you need declare method follows:

create alias your_method "acme.function.yourmethod"; 

this limitation documented under user defined functions follows:

method overloading

multiple methods may bound sql function if class compiled , included in classpath. each java method must have different number of arguments. method overloading not supported when declaring functions source code.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -