Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails - find where value equals NaN

How should I write a query to find records where a value is NaN?

> Person.where(age: NaN)
NameError: uninitialized constant NaN
like image 964
Ollie Glass Avatar asked May 26 '15 11:05

Ollie Glass


2 Answers

You should do:

Person.where(age: Float::NAN)

Check this NAN .

like image 73
Arup Rakshit Avatar answered Sep 17 '22 02:09

Arup Rakshit


If you don't necessarily need to get a AR collection as a result of selection, but will be ok with an array, you can do it like this:

Person.all.select{ |p| p.age.nan? }
like image 33
Andrey Deineko Avatar answered Sep 20 '22 02:09

Andrey Deineko