[HACKERS] Sum aggregate calculation for single precsion real - Mailing list pgsql-hackers

From Konstantin Knizhnik
Subject [HACKERS] Sum aggregate calculation for single precsion real
Date
Msg-id d18bcff9-1bc1-3ef9-9093-7eafdc05173e@postgrespro.ru
Whole thread Raw
Responses Re: [HACKERS] Sum aggregate calculation for single precsion real  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi hackers,

I wonder why SUM aggregate is calculated for real (float4) type using 
floating point accumulator?
It cause very confusing and unexpected behavior:

-- postgres=# select sum(l_quantity)  from lineitem where l_shipdate <= '1998-12-01';     sum
------------- 1.52688e+09
(1 row)

postgres=# select sum(l_quantity+0.0)  from lineitem where l_shipdate <= '1998-12-01';    sum
------------ 1529738036


It is specified in any SQL standard how aggregates should be calculated?
At least Oracle and MS-SQL are calculating SUM for single precision type in different (and more natual) way.
Are there are reasons of using float4pl function for SUM aggregate instead of float4_accum?



Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company




pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: [HACKERS] Documentation improvements for partitioning
Next
From: Stas Kelvich
Date:
Subject: [HACKERS] Walsender crash