Hey Katka,
> How to increase the precision of calculations in posgresql?
>
> When I run this query:
>
> select 5/2;
>
> I get:
>
> ?column?
> --------
> 2
>
> It should be 2.5 shouldn't it?
Nope! You're thinking like a normal person, not like a database engineer.
Translated, here's what you told the database:
Give me INTEGER 5 / INTEGER 2
and the database told you:
INTEGER 2
if you'd asked, the database would also have happily told you:
REMAINDER 1
What you really wanted to ask the database was:
Give me NUMERIC 5 / NUMERIC 2or in SQL:
SELECT 5::NUMERIC/2::NUMERIC
At which point you will get
2.5000 (NUMERIC)
Look for a general book on SQL databases, which should be able to give you a
primer on data types and casting.
--
-Josh BerkusAglio Database SolutionsSan Francisco