Re: Selecting reals into doubles - Mailing list pgsql-general

From Tom Lane
Subject Re: Selecting reals into doubles
Date
Msg-id 12784.1078326269@sss.pgh.pa.us
Whole thread Raw
In response to Selecting reals into doubles  (Will Newton <will@gbdirect.co.uk>)
List pgsql-general
Will Newton <will@gbdirect.co.uk> writes:
> I have attached some SQL which produces what to me, at least, is
> rather unexpected results. Selecting real columns into double
> precision columns loses some precision. Is this expected or documented
> anywhere?

You shouldn't be surprised; this is a fundamental behavior of floating
point arithmetic anywhere.

There isn't any "loss of precision" per se --- the value represented in
the float8 column is the same as what was in the float4 column.  The
difference is that the float8 output routine is programmed to print
about 15 digits of precision whereas the float4 routine prints no more
than 6.  So you get to see the fact that the stored value wasn't really
20.2 but only something close to it.

If you find this surprising maybe you should be using type "numeric".

            regards, tom lane

pgsql-general by date:

Previous
From: "Sally Sally"
Date:
Subject: making a copy of a table within the same database
Next
From: Palle Girgensohn
Date:
Subject: Re: [ANNOUNCE] PostgreSQL 7.3.6 Now Available ...