On 2019-10-21 13:17, Lukas Eder wrote:
> Hi Mark,
>
> Thank you very much for your thorough bug report. I do think this is a
> bug, although I'm not sure if we should:
>
> - Generate an integer value instead of an interval
> - Change the API entirely, as other dialects will probably have a
> similar problem with this particular usage.
>
> A workaround is, as always, to use plain SQL. I would not resort to
> using string concatenation, but the templating functionality instead:
>
>> abs(field("DATEDIFF(DAY FROM {0} TO {1})", SQLDataType.INTEGER,
>> previousPostDate, nextPostDate)).lessOrEqual(1)
Thanks. This was the first time I actually used this particular feature,
and I hadn't seen the templating option.
> Another option is to use Field.coerce(SQLDataType.INTEGER) on your
> datediff expression:
>
>> abs(localDateTimeDiff(previousPostDate,
>> nextPostDate).coerce(INTEGER)).lessOrEqual(oneDay)
>
> Coerce re-assigns a new jOOQ DataType to a Field expression, without
> any impact on the resulting SQL statement.
I'll try that as well. Given I'm checking bad data, and the range of
dates I'm working is occasionally off by years, coercing to BIGINT is
probably better to avoid overflow issues.
> We'll look into how to fix this thoroughly, but you should be able to
> continue working with one of the above workarounds.
Thanks, I'll try and see which option works best for me.
As a related remark, being able to specify the part parameter would be a
great feature as well. The results of DATEDIFF(DAY, ..., ...) and
DATEDIFF(MILLISECOND, ..., ...) are not entirely equivalent as DATEDIFF
only uses the specified part and 'higher' parts for calculating the
difference. For example, DATEDIFF(DAY, timestamp '2019-10-21
23:59:59.999', timestamp '2019-10-22 00:00:00') is 1, but
DATEDIFF(MILLISECOND, timestamp '2019-10-21 23:59:59.999', timestamp
'2019-10-22 00:00:00') is also 1. In my specific use case, this doesn't
really matter, but it might be a relevant difference for example when
using a greaterThan comparison.
Mark