Sign up ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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

I tried something like :

update points set latitude2 = cast(latitude as double) ;

where latitude is a string and latitude2 is a double. I just can't get it to work.

share|improve this question

closed as off-topic by Paul White, Michael Green, RolandoMySQLDBA, Marian, Colin 't Hart May 24 at 19:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – Paul White, Michael Green, RolandoMySQLDBA, Marian
If this question can be reworded to fit the rules in the help center, please edit the question.

"can't get it to work" is not a valid Postgres error message. Please post the complete error (or describe what exactly isn't working) –  a_horse_with_no_name Jul 11 '11 at 7:01

1 Answer 1

double is not a postgres data type:

select cast('324342' as double);
ERROR:  type "double" does not exist

but double precision is:

select cast('132342' as double precision);

(1 row)

So try:

update points set latitude2 = cast(latitude as double precision) ;

if you prefer, you can use float * instead, because according to the docs:

float with no precision specified is taken to mean double precision

select cast('132342' as float);


(1 row)

* or float(n) where 25<=n<=53 because that is also taken to mean double precision

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.