# Storing BigDecimal in the db

**URL:** <https://www.ruby-forum.com/t/storing-bigdecimal-in-the-db/61576>\
**Category:** Rails\
**Created:** [May 25, 2006, 5:19am UTC](https://www.ruby-forum.com/t/storing-bigdecimal-in-the-db/61576 "2006-05-25T05:19:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [May 25, 2006, 5:19am UTC](https://www.ruby-forum.com/t/storing-bigdecimal-in-the-db/61576/1 "2006-05-25T05:19:06Z")

</div>

I need to do some precise math, going to 12-14 decimal places, so I’m  
using BigDecimal. How can I store this in a db? I’m using postgresql  
8.1.0, if that matters at all. I found a plugin [1] but it gives me  
the error “You have a nil object when you didn’t expect it! The error  
occurred while evaluating nil.each\_pair,” with no line number. The  
plugin itself never calls #each\_pair, so it has to be somewhere inside  
Rails or the postgres adapter. I’m using Rails 1.1.2 and the postgres  
0.7.1 adapter.

Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [May 25, 2006, 6:58am UTC](https://www.ruby-forum.com/t/storing-bigdecimal-in-the-db/61576/2 "2006-05-25T06:58:38Z")

</div>

On 5/24/06, Pat M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I found a plugin [1]

Hrm, referenced a link and forgot to include it.

[1] [http://lists.rubyonrails.org/pipermail/rails/2006-April/033425.html](http://lists.rubyonrails.org/pipermail/rails/2006-April/033425.html)

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [May 25, 2006, 3:04pm UTC](https://www.ruby-forum.com/t/storing-bigdecimal-in-the-db/61576/3 "2006-05-25T15:04:12Z")

</div>

On Thursday 25 May 2006 04:16, Pat M. wrote:

> I need to do some precise math, going to 12-14 decimal places, so I’m  
> using BigDecimal. How can I store this in a db? I’m using postgresql  
> 8.1.0, if that matters at all. I found a plugin [1] but it gives me  
> the error “You have a nil object when you didn’t expect it! The error  
> occurred while evaluating nil.each\_pair,” with no line number. The  
> plugin itself never calls #each\_pair, so it has to be somewhere inside  
> Rails or the postgres adapter. I’m using Rails 1.1.2 and the postgres  
> 0.7.1 adapter.

Hi Pat

I wrote that 🙂

Can you be more specific about what you are trying to do? Maybe I can  
help  
track down the issue.

Ashley

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [May 25, 2006, 4:29pm UTC](https://www.ruby-forum.com/t/storing-bigdecimal-in-the-db/61576/4 "2006-05-25T16:29:51Z")

</div>

On 5/25/06, Ashley M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Pat
> 
> - Gregory Chudnovsky
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Hey Ashley,

I’m using Duane J.'s column\_comments plugin [1], and that’s where  
the error popped up. I’m not entirely sure why the error occurs, as I  
just wrapped the problem code in an “unless cols.nil?..end” block.  
Anyway it’s nothing wrong with your plugin. Now schema dumps actually  
work 🙂 Thanks for doing this, and I’ll look into the column\_comments  
plugin and get a solution for Duane.

Pat

[1] [http://blog.inquirylabs.com/2006/04/27/columncomments-rails-plugin/](http://blog.inquirylabs.com/2006/04/27/columncomments-rails-plugin/)
