Re: avg() with floating-point types

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "George Pavlov" <gpavlov(at)mynewplace(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: avg() with floating-point types
Date: 2006-01-02 01:25:50
Message-ID: 26697.1136165150@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"George Pavlov" <gpavlov(at)mynewplace(dot)com> writes:
> The datatype of both city.latitude and postal_code.latitude is
> number(16,12).
> This works, but I would like to understand why there is sometimes a
> discrepancy between avg(pc.latitude) and what actually gets inserted
> into the city table -- is it the usual floating-point discrepancy or is
> there something I can do about it? E.g. after the above update:

You're forcing the result of the avg() calculation to be rounded to 12
digits when you store it into city.latitude. Your example simply shows
that the avg() calculation is being done to more precision than that.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2006-01-02 01:27:41 Re: avg() with floating-point types
Previous Message George Pavlov 2006-01-02 00:40:18 avg() with floating-point types