Re: Selecting reals into doubles

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Will Newton <will(at)gbdirect(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting reals into doubles
Date: 2004-03-03 15:04:29
Message-ID: 12784.1078326269@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Will Newton <will(at)gbdirect(dot)co(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Palle Girgensohn 2004-03-03 15:07:16 Re: [ANNOUNCE] PostgreSQL 7.3.6 Now Available ...
Previous Message Sally Sally 2004-03-03 15:00:14 making a copy of a table within the same database