mysql - Ruby on Rails maximum weird results -


i doing simple call here , i'm unsure why results erratic.

foo.maximum('bar') 

bar looks this

|bar | |----- |16  | |5   | |2   | |10  | |7   | |8   | |10  | |9   | 

i expect call respond maximum value 16. thing noteworthy in respect these values are, because have no way of knowing if going come in int or float, strings. getting max of character value rather numbers themselves?

if can't alter database , need deal strings, in ruby instead. however, may expensive if foo table has ton of stuff in it:

foo.select("bar").collect{|foo| foo.bar.to_f}.max 

or if wanted avoid instantiating bunch of activerecord objects, above code selecting single field:

activerecord::base.connection.query("select bar foo").collect{|foo| foo.first.to_f}.max 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -