|
As of DB2 9.7 the order by clause also supports NULLS FIRST/LAST but currently the DB2Dialect generates a wrong clause. The DB2 grammar allows NULLS LAST only if the order is ASC and NULLS FIRST only if the order is DESC.
If i specify a query that uses ASC NULLS FIRST, the generated query includes the NULLS FIRST, although not required and also wrong. The DESC case is analog.
I propose to overload the method renderOrderByElement in the DB2Dialect to generate the right clause.
public String renderOrderByElement(String expression, String collation, String order, NullPrecedence nulls) {
final StringBuilder orderByElement = new StringBuilder(expression);
if (collation != null) {
orderByElement.append(" ").append(collation);
}
if (order != null) {
orderByElement.append(" ").append(order);
}
if (("asc".equals(order) && nulls == NullPrecedence.LAST) || ("desc".equals(order) && nulls == NullPrecedence.FIRST)) {
orderByElement.append(" nulls ").append(nulls.name().toLowerCase());
}
return orderByElement.toString();
}
|