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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jon Lapham <lapham(at)extracta(dot)com(dot)br>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: explicitly casting return value of avg() to float4
Date: 2002-04-25 19:03:51
Message-ID: 4895.1019761431@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jon Lapham <lapham(at)extracta(dot)com(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Neil Conway 2002-04-25 19:03:53 Re: Performance Issues with count()
Previous Message S Grannis 2002-04-25 18:54:40 Re: Performance Issues with count()