what data type should be returned by sum(float4)

Started by Kouhei Kaigaiover 11 years ago2 messages
#1Kouhei Kaigai
kaigai@ak.jp.nec.com

Hello,

http://www.postgresql.org/docs/devel/static/functions-aggregate.html

The documentation says that return type of sum(expression) is...
bigint for smallint or int arguments, numeric for bigint arguments,
double precision for floating-point arguments, otherwise the same
as the argument data type

Does it expect sum(float4) returns float8, doesn't it?

On the other hand, catalog definition seems to me it returns float4.

postgres=# select * from pg_aggregate where aggfnoid in (2110, 2111);
aggfnoid | aggkind | aggnumdirectargs | aggtransfn | aggfinalfn | aggmtra
nsfn | aggminvtransfn | aggmfinalfn | aggfinalextra | aggmfinalextra | aggsortop
| aggtranstype | aggtransspace | aggmtranstype | aggmtransspace | agginitval |
aggminitval
----------------+---------+------------------+------------+------------+--------
-----+----------------+-------------+---------------+----------------+----------
-+--------------+---------------+---------------+----------------+------------+-
------------
pg_catalog.sum | n | 0 | float4pl | - | -
| - | - | f | f | 0
| 700 | 0 | 0 | 0 | |
pg_catalog.sum | n | 0 | float8pl | - | -
| - | - | f | f | 0
| 701 | 0 | 0 | 0 | |
(2 rows)

Which one shall be fixed?

Thanks,
--
NEC OSS Promotion Center / PG-Strom Project
KaiGai Kohei <kaigai@ak.jp.nec.com>

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Kouhei Kaigai (#1)
Re: what data type should be returned by sum(float4)

Kouhei Kaigai <kaigai@ak.jp.nec.com> writes:

The documentation says that return type of sum(expression) is...
bigint for smallint or int arguments, numeric for bigint arguments,
double precision for floating-point arguments, otherwise the same
as the argument data type

Does it expect sum(float4) returns float8, doesn't it?

Good catch! [ digs in commit history... ] It looks like the claim
that sum(float4) produces float8 was introduced in my commit
d06ebdb8d3425185d7e641d15e45908658a0177d of 2000-07-17; but it seems
to have been an outright error, because sum(float4) was a separate
aggregate long before that. Possibly a copy-and-paste mistake from
some other aggregate? I sure don't remember.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers