It looks like postgres requires Nan and Infinity to be quoted when trying to insert them into a table. This is a tiny patch check for these values by overriding literal_float in the postgres adapter and adding the required quotes.
nan and infinity should be quoted in postgresql
I agree this should be fixed. However, your current patch will hurt performance, since it calls to_s on all Floats, and then does three string comparisons. For better performance, I would recommend something like:
elsif value > 0
elsif value < 0
Your specs should also check for correct results by actually inserting results in a table and reading the results back, not just checking that the expected SQL is produced.
If you can make those changes, I would appreciate it. If not, I'll try to take care of it myself before 3.33.0 is released.
added tests for actual inserting and found the float translator neede…
…d to modified to account for nan and infinity
No problem, thanks for a great library.
I've modified the if statement as you suggested to reduce the work and added tests for the actual insertion and retrieval. I added conversions on the way out of the database in def float. I don't know if it's possible to reduce the comparisons on the way from the database. It might be possible to do something like:
if s.to_f.to_s == s
...check for NaN and Infinity
but that would be two type conversion plus one comparison vs 3 comparisons.
I'll do some microbenchmarking to determine the fastest way. Otherwise, this looks good. I should be able to merge this later today. Thanks for the help!