In memory H2 and postgres date function

2,522 views
Skip to first unread message

petek

unread,
Feb 8, 2012, 2:31:39 AM2/8/12
to H2 Database
Hi,
I'm running H2 in memory in postgres compatibility mode:
jdbc:h2:mem:test;MODE=PostgreSQL

I'm getting a driver error around the DATE function:

org.h2.jdbc.JdbcSQLException: Column "DATE" not found; SQL statement:
Select * from ****** where *******_date < date ? [42122-163]

Looks like driver is not recognising date as a function.
Is this date function not supported by H2 PostgreSQL compatibility
mode ? or am I using the driver incorrectly ?
I've searched user groups & H2 documentation for an answer and havent
got any further.
I undertand H2 is an open source project so I can refer to source
code, but if someone could give me a hand pointing me in the right
direction that would be a great help.
With Thanks
Peter

Peter Yuill

unread,
Feb 8, 2012, 4:15:45 PM2/8/12
to h2-da...@googlegroups.com
Hi Peter,

> Hi,
> I'm running H2 in memory in postgres compatibility mode:
> jdbc:h2:mem:test;MODE=PostgreSQL
>
> I'm getting a driver error around the DATE function:
>
> org.h2.jdbc.JdbcSQLException: Column "DATE" not found; SQL statement:
> Select * from ****** where *******_date< date ? [42122-163]
>
> Looks like driver is not recognising date as a function.
> Is this date function not supported by H2 PostgreSQL compatibility
> mode ? or am I using the driver incorrectly ?

DATE is a legacy function in PostgreSQL, use CURRENT_DATE or
CURRENT_TIMESTAMP instead (supported in both H2 and PostgreSQL)

Regards,
Peter

Peter Yuill

unread,
Feb 8, 2012, 5:09:03 PM2/8/12
to h2-da...@googlegroups.com
Hi Peter,

> org.h2.jdbc.JdbcSQLException: Column "DATE" not found; SQL statement:
> Select * from ****** where *******_date< date ? [42122-163]

Should have taken the time to wake up. The date literal in H2 cannot
take a parameter as PostgreSQL does. There is no directly compatible syntax.

Regards,
Peter

Thomas Mueller

unread,
Feb 9, 2012, 12:27:55 AM2/9/12
to h2-da...@googlegroups.com
Hi,

You are using invalid syntax. Try:

* from ****** where *******_date < ?

(remove the keyword "date"). This will work in both PosgreSQL and H2
(and other databases).

Regards,
Thomas

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

petek

unread,
Feb 17, 2012, 6:59:18 AM2/17/12
to H2 Database
Thanks a lot for your help with this.
Looks like I'll have to sort out the legacy SQL before switching to an
in memory DB for unit tests.
A job thats well overdue !!
With Thanks
Peter

On Feb 9, 5:27 am, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:
> Hi,
>
> You are using invalid syntax. Try:
>
>     * from ****** where *******_date < ?
>
> (remove the keyword "date"). This will work in both PosgreSQL and H2
> (and other databases).
>
> Regards,
> Thomas
>
> On Wed, Feb 8, 2012 at 8:31 AM, petek <peteka...@gmail.com> wrote:
> > Hi,
> > I'm running H2 in memory inpostgrescompatibility mode:
Reply all
Reply to author
Forward
0 new messages