Search Postgresql Archives

Re: Rounding problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Paolo Saudin wrote:

Hi,

 

I have a problem with a query wich simple aggregate values. In the sample below I have two values, 1.3 and 1.4. Rounding their average with one decimals, should give 1.4.

The first query with  -  cast( tables_seb.tbl_arvier_chamencon.id_1  AS numeric) AS value  - give the expected result, while the second one with - tables_seb.tbl_arvier_chamencon.id_1 AS value - give 1.3.

 

Which could be the reason ??

 


My first thought is whats with all the castings???  

Castings  are mostly likely the cause of your problems,   What is tbl_arvier_chamencon.id_1 data type???

I'm guessing its something other than numeric. All other floating point data types will have problems caused by Binary Floating-Point Arithmetic

Numeric data type uses different functions to do its math for the stated purpose of being exact yet being allot slower.

In one query casting is done prior to avg() yet in the other casting is done after avg().   This will allow Postgres to use different functions to calculate average giving an unexpected result.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux