-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PostgreSQL] Retrieve NUMERIC and DECIMAL as a more compatible Kotlin type #1882
Comments
I think ideal case is we have a postgres-specific runtime which has some sort of sealed class that encapsulates all the numeric types |
The key feature of the NUMERIC datatype in postgres isn't so much that it can handle huge numbers (though some folks probably use that feature), but that it is exact. Real and double-precision types are inexact which means numbers after the decimal may change at times in unpleasantly surprising ways. If you could add support for Numeric types that fit in a Double that would probably cover 90% of use cases. Folks who need larger numbers could have another way to adapt the value to java. |
@tropikoder I agree that In the long term, I'd probably go with something like @AlecStrong's suggestion: sealed class Numeric {
object PositiveInfinity : Numeric()
object NegativeInfinity : Numeric()
object NaN : Numeric()
data class Finite(val value: BigDecimal) : Numeric()
} |
We currently retrieve
NUMERIC
andDECIMAL
askotlin.Long
, but this kt type doesn't correctly encapsulateNUMERIC
norDECIMAL
, as both these types:kotlin.Long
bounds ("up to 131072 digits before the decimal point; up to 16383 digits after the decimal point").Infinity
,-Infinity
, orNaN
.I can't think of a data type that abides by all three constraints. Exposing the type as
BigDecimal
would be a step in the right direction, but it doesn't supportInfinity
,-Infinity
, orNaN
. The only valid solution that I can currently think of is exposing the type as aString
, and put the burden on the user to have a custom adapter that meets their constraints (for example, they can useBigDecimal
if they don't care about the third constraint).The text was updated successfully, but these errors were encountered: