I am doing a simple call here and I’m unsure why my results are so erratic.
Foo.maximum('bar')
bar looks like this
|bar |
|-----
|16 |
|5 |
|2 |
|10 |
|7 |
|8 |
|10 |
|9 |
I would expect the call to respond that the maximum value is 16. The only thing noteworthy in respect to these values is that they are, because I have no way of knowing if they are going to come in as an int or a float, actually strings. Could it be getting the max of the character value rather than the numbers themselves?
If you can’t alter the database and need to deal with strings, you could do something in ruby instead. However, it may be expensive if your
Footable has a ton of stuff in it:Or if you wanted to avoid instantiating a bunch of ActiveRecord objects, which the above code would do even with just selecting a single field: