# \-Infinity for Doule type column

**URL:** <https://www.ruby-forum.com/t/infinity-for-doule-type-column/98052>\
**Category:** Rails\
**Created:** [July 12, 2006, 7:39am UTC](https://www.ruby-forum.com/t/infinity-for-doule-type-column/98052 "2006-07-12T07:39:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pool007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3bc359/32.png) [@pool007](https://www.ruby-forum.com/u/pool007)\
**Post date:** [July 12, 2006, 7:39am UTC](https://www.ruby-forum.com/t/infinity-for-doule-type-column/98052/1 "2006-07-12T07:39:42Z")

</div>

Hi list.

I’m writing a program that stores a lot of Floats into MySQL database.  
Simplified version of the program use the following form of class.

class Val \< ActiveRecord::BASE  
end

And Vals table contains one column:

num double

One of my data contains -Infinity for num and when I try to  
Val.new  
Val.num = \<- Here goes -Inifinity  
Val.save!

Then the program crashes:  
“/usr/local/stow/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active\_record/connection\_adapters/abstract\_adapter.rb:120:in  
`log': Mysql::Error: Unknown column 'Infinity' in 'field list': INSERT INTO full_doc_indices (`etf`,`Id`,`phonemes`,`filename`,`end\_time`,`start\_time`) VALUES(-Infinity, NULL, ‘IH N T IH’, ‘BN99EN\_2’,  
4952.77044, 4939.515) (ActiveRecord::StatementInvalid)”

Obviously, ActiveRecord is using “-Infinity” literally, and then MySQL  
treats “-Infinity” as column name as the message shows. How can I handle  
-Infinity then? I really have to store -Infinity anyway.

Thanks.

Sincerely,  
Minkoo S.

---

<div class="post-metadata">

**Author:** ![pool007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3bc359/32.png) [@pool007](https://www.ruby-forum.com/u/pool007)\
**Post date:** [July 12, 2006, 11:27am UTC](https://www.ruby-forum.com/t/infinity-for-doule-type-column/98052/2 "2006-07-12T11:27:28Z")

</div>

Ruby does not seem to have a good way of representing infinity in  
floats. “(1.0/0.0).inifinite?” is more about checking an overflow.

One solution would be to create another column in the table called  
inifinity that could be 0 for not infinite, 1 for positive infinity,  
and 2 for negative infinity. You would only check the actual Val  
column if infinity was 0.

You would then write a method in your model that converts from your  
value to the two database columns. Lookup up facade columns for one  
way to do this.

```
        - dan

```

–  
Dan K. [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.dankohn.com/](http://www.dankohn.com/)tel:+1-415-233-1000
