Sum aggregate calculation for single precsion real

From: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Sum aggregate calculation for single precsion real
Date: 2017-02-13 11:13:41
Message-ID: d18bcff9-1bc1-3ef9-9093-7eafdc05173e@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stas Kelvich 2017-02-13 11:55:31 Walsender crash
Previous Message Amit Langote 2017-02-13 10:57:59 Re: Documentation improvements for partitioning