Hi, I'd like to create a query with two order like...
# exposed
a
Hi, I'd like to create a query with two order like this (PostgreSQL style): SELECT * FROM country ORDER BY CASE when country.code='HU' then 0 ELSE 1 END , country.name ASC There is a
Copy code
class CaseWhenElse<T>
which sounds good to me, but I failed to create: CountryTable.selectAll().orderBy( ??? CaseWhenElse ??).orderBy(CountryTable.name, SortOrder.ASC) Could help me out someone who already did that? Thanks
1
c
Hi @Attila Here you go:
Copy code
val caseCondition = Case()
    .When(Op.build { CountryTable.code eq "HU" }, intLiteral(0))
    // more .When() branches
    .Else(intLiteral(1))

CountryTable
    .selectAll()
    .orderBy(caseCondition)
    .orderBy(CountryTable.name, SortOrder.ASC)
If you want to use the
CaseWhenElse
constructor instead, here's how:
Copy code
val caseCondition2 = CaseWhenElse(
    caseWhen = Case().When(Op.build { CountryTable.code eq "HU" }, intLiteral(0)),
    elseResult = intLiteral(1)
)
1
a
AWESOME! 😄 Thank you Chantal! Happy Holidays! Best regards, Attila
c
Same to you kodee greetings