Current response a-z A-Z Needed as aA-zZ or Aa-Zz
Code line : return select -> select.orderBy(sortFields); Note : where sortFields is List<OrderField> sortFields = new ArrayList>()
tried using DSL.lower menthod but it saying to convert sortFields as string. Code line : return select -> select.orderBy(lower(sortFields));
sortFields is in the reference of List<OrderField<?>> is there any way to get sorting as case insensitive to get response as (aA-zZ or Aa-Zz)
CodePudding user response:
Look at the method signatures:
You can't just combine them, they accept different types. The ORDER BY
clause accepts a collection (or varargs array) of OrderField
(Field<?>
being a valid subtype), whereas LOWER()
is a scalar function accepting only a single field. You can't just LOWER()
a collection of fields. Also, you can't LOWER()
a SortField
, which could be something like TABLE.COLUMN.asc()
.
I don't know why your original data structure has to be List<OrderField>
. Are you maintaining that list somewhere to create dynamic SQL, including dynamic ASC
/ DESC
sort order?
In any case, you will have to apply the LOWER()
function to each field individually, e.g.:
List<Field<?>> sortFields = ...
select.orderBy(sortFields.stream().map(f -> lower(f)).toList())
And if you have dynamic ASC
/ DESC
sort directions, you'll have to apply that after calling lower(f)
to each position.
As a side note, collations are the SQL idiomatic way to implement case insensitive ordering, maybe better use that.
CodePudding user response:
Finally found the answer for this by adding Field orderFieldSort = lower((Field) orderField);