I've changed some of the relevant code to use TIMESTAMPADD, so that
problem is solved - but why did I get an error after registering the
function? I tried calling it only with strings (like this:
DATE_ADD("2012-01-01","INTERVAL 7 DAY") ) and it still won't run.

Its important for me to know how to add functions because I want to be
able to add workaround for missing MySQL compatible functions that we
use in our code.

On Apr 29, 6:10 pm, Thomas Mueller <[email protected]>
wrote:
> I'm sorry but H2 does not support the syntax "INTERVAL 7 DAY". So even
> if you could create the DATE_ADD function, it still wouldn't work. As
> a workaround, you can use TIMESTAMPADD. This function is already
> supported in H2, and works the same way as in MySQL:

> On Wed, Apr 25, 2012 at 8:47 AM, Oded Arbel <[email protected]> wrote:
> > Hi Guys.
>
> > I'm trying to use H2 embedded in the Java application to run some code
> > that was written with MySQL in mind. Specifically it is using MySQL's
> > DATE_ADD function a lot.
>
> > I though I can just write something that works like DATE_ADD and load
> > it into the database (changing the code is not really an option). So I
> > created a class:
>
> > package com.taboola.h2;
>
> > public class Functions {
> >  public static java.sql.Date dateAdd(java.sql.Date originalDate,
> > String interval) {
> >    java.sql.Date out;
> >    // .. do something
> >    return out;
> >  }
> > }
>
> > I then execute this when I set up the database:
> > Statement s = connection.createStatement();
> > st.executeUpdate("CREATE ALIAS DATE_ADD FOR
> > \"com.taboola.h2.Functions.dateAdd\"");
> > st.close();
>
> > The above code executes without errors, but when I go and execute the
> > SQL code, it still fails with the error that DATE_ADD is not a
> > recognized function.
>
> > Some sample SQL is this code to check for users that have logged in
> > recently:
> > SELECT * FROM apps.user_login_log WHERE NOW() <=
> > DATE_ADD(last_login_time, INTERVAL 7 DAY) ORDER BY last_login_time
>
> > What am I doing wrong here?
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "H2 Database" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group 
> > athttp://groups.google.com/group/h2-database?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to