Re: Selecting reals into doubles

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Selecting reals into doubles
Дата
Msg-id 12784.1078326269@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Selecting reals into doubles  (Will Newton <will@gbdirect.co.uk>)
Список 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 по дате отправления:

Предыдущее
От: "Sally Sally"
Дата:
Сообщение: making a copy of a table within the same database
Следующее
От: Palle Girgensohn
Дата:
Сообщение: Re: [ANNOUNCE] PostgreSQL 7.3.6 Now Available ...