Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

#count on decimal column returns BigDecimal #784

Closed
lighthouse-import opened this Issue May 16, 2011 · 12 comments

Comments

Projects
None yet
1 participant

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6158
Created by qertoip - 2010-12-13 15:44:24 UTC

Salary.count( :amount ) # => BigDecimal instead of Fixnum

Imported from Lighthouse.
Comment by Jarrett Meyer - 2010-12-13 20:21:10 UTC

Verified on Ubuntu + sqlite3
ruby-1.9.2-p0 > c = Person.count(:salary)
=> #BigDecimal:1a30a38,'0.1E1',9(18)

Imported from Lighthouse.
Comment by Jarrett Meyer - 2010-12-13 20:57:46 UTC

Added patch. Contains broken unit test and code to fix it.

Imported from Lighthouse.
Comment by Thomas van der Pol - 2011-02-15 09:30:34 UTC

I could not replicate this problem with Rails 3.0.4 on Mac OS 10.6 with ruby 1.9.2p136

Steps:

  1. Create new rails app (with sqlite3 as the db adapter - default)
  2. generate model with decimal column
  3. in rails console, create a few entries
  4. TestModel.count(:decimal_column) returned an integer count, not a BigDecimal

As such, I did not try the patch. If this only happens on specific versions of rails, let me know and I'll test on them, as well.

Imported from Lighthouse.
Comment by Josh Kalderimis - 2011-02-15 16:42:40 UTC

Hey qertoip,

Is this a DB specific issue? or were the sqlite tests also failing with your test case?

Josh

Imported from Lighthouse.
Comment by Thomas van der Pol - 2011-02-17 12:03:11 UTC

As per Josh K's request, I checked the same setup as above in Postgres. (Postgres 9.0.3 on aforementioned platform: Rails 3.0.4 on Mac OS 10.6 with ruby 1.9.2p136)

The outcome is the same:

Salary.count(:amount).class => Fixnum

Where Salary.amount is a decimal column in the migration, a 'numeric' type in the database itself (default behaviour).

Cheers,
Thomas

Imported from Lighthouse.
Comment by Josh Kalderimis - 2011-02-17 12:07:28 UTC

Hey qertoip and Jarrett,

I am marking this issue as need-more-info until more information is supplied on how to replicate the issue.

Thanks,

Josh

Imported from Lighthouse.
Comment by Jarrett Meyer - 2011-02-17 13:43:40 UTC

It looks like a different patch was applied to fix a similar problem that also fixed this problem - see ticket 6103.

If I'm reading the git history correctly, this was fixed on Jan 10, 2011. The unit test in my patch file now passes. (Although there is no such unit test currently in 3.0.4.)

Imported from Lighthouse.
Comment by Josh Kalderimis - 2011-02-17 13:49:39 UTC

Hi Jarrett,

Thanks for looking into this, can you please create a new patch which only includes a test to make sure this does not break in the future. I will then get José or Santiago to look into it further.

Thanks

Josh

Imported from Lighthouse.
Comment by Jarrett Meyer - 2011-02-18 15:05:14 UTC

Added patch file with just the unit test.

Imported from Lighthouse.
Comment by karle durante - 2011-03-01 18:59:57 UTC

We use Rails w/ Oracle and have also started seeing that Model.count returns BigDecimal, as opposed to Integer.

Seems this was introduced with Rails 2.3.8 and persists in 2.3.11.

Imported from Lighthouse.
Comment by Josh Kalderimis - 2011-03-02 15:37:34 UTC

@karle: As this is not a security issue it will not be applied to 2.3.x branch.

@jarrett: I just wanted to check, have you confirmed if this is an issue on 3-0-stable and master, or just 3.0.4?

Thanks

Josh

Attachments saved to Gist: http://gist.github.com/971749

@hisas hisas pushed a commit to hisas/rails that referenced this issue May 9, 2017

@jeremy jeremy Merge pull request #784 from mikel/revert-767-grosser/Windows1258
Revert "support windows-1258"
ab0c643
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment