https://kotlinlang.org logo
Title
p

Pavel Naumov

02/06/2023, 10:02 AM
hello everyone, i'm stuck with .sum() aggregate function. I have a column of type ushort and i have a query which should retrieve a sum of the column values. Even though the values are ushort (SMALLINT UNSIGNED) resulted sum might be out of the ushort range. And for plain MariaDB query in console it's absolutely legit query. But
MyTable.uShortCol.sum()
truncates result to ushort, obviously. Any adwise? I've found an issue on the GitGub https://github.com/JetBrains/Exposed/issues/1035 which seems relevant to me but there's no solution
i've managed to get a correct sum with
MyTable.uShortCol.sum().castTo<Int>(IntegerColumnType())
And it's fine to me. But
MyTable.uShortCol.sum().castTo<UInt>(UIntegerColumnType())
didn't work because generated SQL query was incorrect
CAST(SUM(MyTable.uShortCol) AS INT UNSIGNED) b FROM
s

spand

02/06/2023, 3:03 PM
Why is that sql incorrect?
p

Pavel Naumov

02/06/2023, 4:41 PM
because of
UNSIGNED
inside the
CAST
. It throws mysql error in my case (MariaDB 10.10)
s

spand

02/06/2023, 6:58 PM
Looks like a bug in exposed