Skip to content

SAFE_TO_DOUBLE

Return a DOUBLE PRECISION value from a VARCHAR string that represents a number.

SAFE_TO_DOUBLE(input_number varchar)

The input VARCHAR string is the only argument to this function. If the input is NULL, the function returns NULL. If any parsing or conversion errors occur, this function returns 0.0.

For example:

premdb=# select safe_to_double('39.23789');
 safe_to_double 
----------------
      39.23789
(1 row)

premdb=# select safe_to_double('1000000000000000');
 safe_to_double 
----------------
         1e+15
(1 row)

Parent topic:Type-Safe Casting Functions