Hi: The gist of my question: is there a way to *portably* store and retrieve Infinity in an ActiveRecord float column?
Following is an amusing saga, but it doesn't really answer the question. Step 1: As was mentioned in http://www.ruby-forum.com/topic/74141, you can't simply write a Ruby infinite value. Here are the results in Rails 3 with the sqlite 1.3.3 gem: >> r = TestRec.create(:x => (1.0/0.0)) ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: Infinity: INSERT INTO "test_recs" ("x") VALUES (Infinity) Step 2: So if storing infinity isn't possible, how about a really big value, like Float::MAX? >> r = TestRec.create(:x => Float::MAX) => #<TestRec id: 1, x: 1.7976931348623157e+308> >> r.x == Float::MAX => true Step 3: That looks promising, but we're looking at the in-memory version of the record. We should reload r to get the value from the database: >> r.reload => #<TestRec id: 1, x: Infinity> >> r.x == Float::MAX => false >> r.x.infinite? => 1 Whoa! x has changed from Float::MAX to Infinity. So it appears that if you want to store Infinity in a DB column, you need to store Float::MAX instead. At least for sqlite. Naturally, I don't trust this as a general solution. Can I assume it will work this way across other DBs? If not, is there a generally portable way to store Infinity? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.