Skip to main content
Question

Testing for NaN with FLOAT

  • April 11, 2022
  • 1 reply
  • 3 views

mark_d_drake
Forum|alt.badge.img+1
 select cast(double_precision_col as varchar(39)) , case when double_precision_col = 'NAN' then NULL else cast(double_precision_col as numeric(616,308)) end from t_postgres.numeric_types;

returns

ERROR 3425:  Float "NaN" is out of range for type numeric(616,308)

But according to https://www.vertica.com/blog/vertica-quick-tip-query-nan-values/ I don't see why ?

1 reply

mosheg
Forum|alt.badge.img+2
  • Participating Frequently
  • April 11, 2022

The right way to check if something is NaN is to ask if it is not equal to itself, like mentioned in the tip.
For example:
select case when (616308)::numeric != (616308)::numeric then NULL else (616308)::numeric end from dual;