Hi,

I would like to share a feature of JOOQ, which can lead to an invalid SQL 
in case of Postgres for example.
The following code snippet will generate an invalid SQL:

Jooq Java:

java.sql.Date theDate = ...
cast(dateAdd(value(theDate), inline(10)), Timestamp.class)


Generated SQL:
cast((? + (10 || ' day')::interval)::date as timestamp)

The problem is caused by the missing cast of the bound parameter, which is 
a date. Without the explicit cast the date aritmethics (the dateAdd(...) 
function) will not work and the SQL will fail.
Correct SQL is:
cast((cast(? as date) + (10 || ' day')::interval)::date as timestamp)

Reason of the problem:
The context's CastMode is set to NEVER in the inner part of a cast, so 
there will be no nested casts (in the org.jooq.impl.Cast.Native class)

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to