Overriding TO_DATE function

995 views
Skip to first unread message

Marius Popescu

unread,
Dec 8, 2021, 6:22:18 AM12/8/21
to H2 Database
Hi all,
 I am using Oracle and H2 1.4.200 for in memory tests. In a query we are using TO_DATE with an implicit default 'yyyy-MM-dd' and I would like this to keep it this way on H2 as well. 

 I have tried this :

drop ALIAS if exists TO_DATE; 
  CREATE ALIAS TO_DATE as '
  import java.text.*; 
@CODE java.util.Date toDate(String s) throws Exception {
  return new SimpleDateFormat("yyyy-MM-dd").parse(s); 
 } ' 

But I get : 90076-200 Function "TO_DATE" already exists.
If I try to drop it without 'if exists' it says that it does not exist.

Any idea how to fix this or other option to change from H2 default DD MON YYYY to the another one ?

Tks,
Marius

Evgenij Ryazanov

unread,
Dec 8, 2021, 6:40:20 AM12/8/21
to H2 Database
Hello.

You cannot drop a built-in function and they are not aliases.

But you can override them with alias. You need to append
;BUILTIN_ALIAS_OVERRIDE=TRUE
to JDBC connection URL.
Reply all
Reply to author
Forward
0 new messages