Home > Software design >  Converting a string to a double precision in PostgreSQL
Converting a string to a double precision in PostgreSQL

Time:08-04

How can I convert a string 17,74320512 to a double precision in PostgreSQL ?

I tried:

select cast(`17,74320512` as double precision);

ERROR: invalid syntax for double precision type: '17,74320512'

But i can not change format of the number(17,74320512) because i imported it from .txt file

CodePudding user response:

Use to_number() and chose the format that best suits your strings and locale, e.g.

SELECT 
  to_number('17,74320512','999D99999999'),
  to_number('17,74320512','999D99999999')::double precision;

  to_number  |  to_number  
------------- -------------
 17.74320512 | 17.74320512
  • Related