5

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

> Person.where(age: NaN)
NameError: uninitialized constant NaN
Ollie Glass
  • 18,565
  • 20
  • 70
  • 101

2 Answers2

5

You should do:

Person.where(age: Float::NAN)

Check this NAN .

Arup Rakshit
  • 113,563
  • 27
  • 250
  • 306
1

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? }
Andrey Deineko
  • 49,444
  • 10
  • 105
  • 134