-
Notifications
You must be signed in to change notification settings - Fork 72
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
[Bug?] Performing SUM function on integer column returns BigDecimal result #36
Comments
Casting to an Integer when SUMming int columns makes sense to me. I don't think it's too difficult (we already get back information about whether the column includes decimals). I can open a PR later today. |
Awesome, thanks Daniel! 🙏 ❤️ |
Prior to this commit we'd always cast a SUM query to `BigDecimal`, since the column type we get from the server is 246 (i.e. TRILOGY_TYPE_NEWDECIMAL). After this commit we'll only cast to `BigDecimal` if there are decimal values. If there are none (i.e. if column->decimals is 0), we cast to `Integer` instead. Closes #36
Prior to this commit we'd always cast a SUM query to `BigDecimal`, since the column type we get from the server is 246 (i.e. TRILOGY_TYPE_NEWDECIMAL). After this commit we'll only cast to `BigDecimal` if there are decimal values. If there are none (i.e. if column->decimals is 0), we cast to `Integer` instead. Closes #36
Prior to this commit we'd always cast a SUM query to `BigDecimal`, since the column type we get from the server is 246 (i.e. TRILOGY_TYPE_NEWDECIMAL). After this commit we'll only cast to `BigDecimal` if there are digits in the decimal place. If there are none (i.e. if column->decimals is 0), we cast to `Integer` instead. Closes #36
Fwiw, this is part of how MySQL itself functions. A This is different from I'd argue to be honest here that Sorbet is wrong here. It should expect a |
I vaguely recall wanting to do this to match what the mysql2 gem does, to make it easier for folks switching over from that gem. We decided against making this change at GitHub and made it configurable in #60, in case that is helpful. |
Hi folks!
Encountering something a bit odd -- when performing
SUM
functions, the result is returned as aBigDecimal
. A simple repro:I'm wondering if this is a bug, or if I'm just missing a query option to cast the result to an Integer properly. At Shopify we're using Sorbet, and it complains loudly if a query ends up returning a
BigDecimal
when it was expecting anInteger
.Appreciate the help! ❤️
The text was updated successfully, but these errors were encountered: