Skip to content
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

Do not cast decimal to integer #563

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gmile
Copy link

@gmile gmile commented Nov 22, 2014

This reverts a099e55, where regression has been introduced.

Fixes #557.

@gmile
Copy link
Author

gmile commented Nov 22, 2014

Looks like CI failure is not related?

@sodabrew
Copy link
Collaborator

Yes, the CI issue was unrelated. I just fixed it in e91d8ed.

Since this behavior has been in 0.3.x for a long time, I'm going to tag the revert for 0.4.0. I'm concerned if there will be other fallout / what motivated the change in the first place.

@sodabrew sodabrew added this to the 0.4.0 milestone Nov 24, 2014
@gmile
Copy link
Author

gmile commented Nov 24, 2014

@sodabrew as per author's commit message,

aggregate functions like SUM will produce decimals even when summing integers

Obviously this was the initial intention – to not end up having decimals returned, once aggregating SUM in MySQL.

However, to me sticking with whatever types MySQL returns, would mean "playing by MySQL's rules". Conforming with MySQL sounds like the rights thing to do, as it reduces possible side effects like the one we've seen here.

@sodabrew
Copy link
Collaborator

I read that in the commit but it didn't compute it my head :) I found it in the docs:

http://dev.mysql.com/doc/refman/5.1/en/group-by-functions.html

For numeric arguments, the variance and standard deviation functions return a DOUBLE value. The SUM() and AVG() functions return a DECIMAL value for exact-value arguments (integer or DECIMAL), and a DOUBLE value for approximate-value arguments (FLOAT or DOUBLE).

Well, on the one hand I agree that we should play by MySQL's rules. On the other hand, it seems more surprising to get a DECIMAL back from SUM(bunch of integers) and probably a more common trip-up for users.

I wonder if there's a reasonable workaround to get both behaviors.

@sodabrew sodabrew removed this from the 0.4.0 milestone Jul 31, 2015
@sodabrew
Copy link
Collaborator

I'm not really sure how to proceed here. I don't have a good sense if people are now expecting the >=0.3.11 behavior, or if it's reasonable to choose the behavior as a query_option.

I suppose the simplest thing would just me to merge this and see if anybody shouts about 0.4.0... 🙊

Could I ask you to rebase this against current master, and to add a unit test?

@sodabrew sodabrew added this to the 0.4.0 milestone Jul 31, 2015
@sodabrew sodabrew modified the milestones: 0.4.0, 0.4.1 Sep 4, 2015
@sodabrew sodabrew modified the milestones: 0.4.1, 0.4.2 Sep 15, 2015
@sodabrew sodabrew modified the milestones: 0.4.2, 0.4.3 Nov 22, 2015
@sodabrew sodabrew modified the milestones: 0.4.3, 0.4.4 Feb 24, 2016
@sodabrew sodabrew modified the milestones: 0.4.4, 0.4.5 Mar 6, 2016
@sodabrew sodabrew removed this from the 0.4.4 milestone Mar 6, 2016
@sodabrew sodabrew modified the milestones: 0.4.5, 0.5.0 Oct 22, 2016
@sodabrew sodabrew modified the milestones: 0.5.0, 0.6.0 Mar 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Column created as :decimal being treated as :integer on mysql with default: 0.0
2 participants