kmj
kmj

Reputation: 15

Converting a string to a double precision in PostgreSQL

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

Upvotes: 1

Views: 730

Answers (1)

Jim Jones
Jim Jones

Reputation: 19623

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

Upvotes: 1

Related Questions