This project is archived and is in readonly mode.

#6158 needs-more-info

#count on decimal column returns BigDecimal

Reported by qertoip | December 13th, 2010 @ 03:44 PM

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

Comments and changes to this ticket

  • Jarrett Meyer

    Jarrett Meyer December 13th, 2010 @ 08:21 PM

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

  • Jarrett Meyer

    Jarrett Meyer December 13th, 2010 @ 08:57 PM

    • Tag set to patch

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

  • Thomas van der Pol

    Thomas van der Pol February 15th, 2011 @ 09:30 AM

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


    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.

  • Josh Kalderimis

    Josh Kalderimis February 15th, 2011 @ 04:42 PM

    • Importance changed from “” to “Low”

    Hey qertoip,

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


  • Thomas van der Pol

    Thomas van der Pol February 17th, 2011 @ 12:03 PM

    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).


  • Josh Kalderimis

    Josh Kalderimis February 17th, 2011 @ 12:07 PM

    • State changed from “new” to “needs-more-info”
    • Tag changed from patch to active_record
    • Assigned user set to “Josh Kalderimis”

    Hey qertoip and Jarrett,

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



  • Jarrett Meyer

    Jarrett Meyer February 17th, 2011 @ 01:43 PM

    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.)

  • Josh Kalderimis

    Josh Kalderimis February 17th, 2011 @ 01:49 PM

    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.



  • Jarrett Meyer
  • karle durante

    karle durante March 1st, 2011 @ 06:59 PM

    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.

  • Josh Kalderimis

    Josh Kalderimis March 2nd, 2011 @ 03:37 PM

    @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?



Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by