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
  • 19,455
  • 21
  • 76
  • 107

2 Answers2

5

You should do:

Person.where(age: Float::NAN)

Check this NAN .

Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
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
  • 51,333
  • 10
  • 112
  • 145