Re: explicitly casting return value of avg() to float4

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: explicitly casting return value of avg() to float4
Дата
Msg-id 4895.1019761431@sss.pgh.pa.us
обсуждение исходный текст
Ответ на explicitly casting return value of avg() to float4  (Jon Lapham <lapham@extracta.com.br>)
Список pgsql-general
Jon Lapham <lapham@extracta.com.br> writes:
> Is the preferred way to return the average of ::float4 values to
> explicitly cast the returned value of avg() to ::float4?

Yeah, if you want it to float4 precision.  The internal arithmetic
is always done in float8 to try to minimize cancellation problems.

> main_v0_8=# select avg(0.01::float4);
>           avg
> ---------------------
>   0.00999999977648258
> (1 row)

This isn't really any different from

regression=# select 0.01::float4::float8;
       float8
---------------------
 0.00999999977648258
(1 row)


            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Neil Conway
Дата:
Сообщение: Re: Performance Issues with count()
Следующее
От: Grant Johnson
Дата:
Сообщение: Re: Performance Issues with count()