0

I have a column latitude of type real in my Postgres table.

Looking at it in Postico, it has the value of 57.70887. But selecting it from psql or via code, the value returned is rounded to 4 decimal places:

# SELECT latitude from categories where id = 4;

 latitude
----------
  57.7089
(1 row)

What am I doing wrong?

Postgres 9.6.

3
  • 1
    extra_float_digits Commented Mar 16, 2018 at 9:52
  • @a_horse_with_no_name Thank you, that is correct. SET extra_float_digits = 3;select ..57.7088699. I'll accept it if you post it as an answer :) Commented Mar 16, 2018 at 10:18
  • 2
    @Znarkus just a off topic hint: if you're storing latitudes, I assume you're dealing with longitudes too ;-) so I would really recommend you to use the postgis extension for storing points. I might seem in the beginning a bit unnecessary, but when spatial queries are involved, it can absolutely save you a lot of trouble. Cheers :-) Commented Mar 16, 2018 at 11:25

1 Answer 1

0

The column should not be real if you care for precision. Floating point types only store approximate values. Use numeric instead to preserve the value exactly as inserted.

Consider:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.