Transition functions for SUM(::int2), SUM(::int4, SUM(::int8])

Started by Caleb Weltonalmost 18 years ago4 messages
#1Caleb Welton
cwelton@greenplum.com

Is there any reason that int2_sum, int4_sum, and int8_sum are not marked as
being strict? All the other transition functions for sum, and every other
built in aggregation function is marked as strict, as demonstrated with:

select x.proname, t.proname, t.proisstrict
from ((pg_aggregate a left join
pg_proc x on (a.aggfnoid = x.oid)) left join
pg_proc t on (a.aggtransfn = t.oid))
where not t.proisstrict;

proname | proname | proisstrict
---------+----------+-------------
sum | int2_sum | f
sum | int4_sum | f
sum | int8_sum | f

select x.proname, t.proname, t.proisstrict
from ((pg_aggregate a left join
pg_proc x on (a.aggfnoid = x.oid)) left join
pg_proc t on (a.aggtransfn = t.oid))
where x.proname = 'sum';

proname | proname | proisstrict
---------+-------------+-------------
sum | int8_sum | f
sum | int4_sum | f
sum | int2_sum | f
sum | float4pl | t
sum | float8pl | t
sum | cash_pl | t
sum | interval_pl | t
sum | numeric_add | t
(8 rows)

Thanks,
Caleb

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Caleb Welton (#1)
Re: Transition functions for SUM(::int2), SUM(::int4, SUM(::int8])

Caleb Welton <cwelton@greenplum.com> writes:

Is there any reason that int2_sum, int4_sum, and int8_sum are not marked as
being strict?

They wouldn't work otherwise, because the transition datatypes aren't
the same as the inputs.

regards, tom lane

#3Caleb Welton
cwelton@greenplum.com
In reply to: Tom Lane (#2)
Re: Transition functions for SUM(::int2), SUM(::int4, SUM(::int8])

Thanks Tom,

Forgive me if I'm being dense, but could you explain why

int4_sum(bigint,int) must not be strict, but
int4_avg_accum(bytea, int) can be strict?

It seems that both of them have transition datatypes that are different from
the input.

-Caleb

On 1/28/08 7:31 PM, "Tom Lane" <tgl@sss.pgh.pa.us> wrote:

Show quoted text

Caleb Welton <cwelton@greenplum.com> writes:

Is there any reason that int2_sum, int4_sum, and int8_sum are not marked as
being strict?

They wouldn't work otherwise, because the transition datatypes aren't
the same as the inputs.

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Caleb Welton (#3)
Re: Transition functions for SUM(::int2), SUM(::int4, SUM(::int8])

Caleb Welton <cwelton@greenplum.com> writes:

Forgive me if I'm being dense, but could you explain why

int4_sum(bigint,int) must not be strict, but
int4_avg_accum(bytea, int) can be strict?

The former is used with a NULL initial value, the latter isn't.
Read the fine print in the CREATE AGGREGATE man page about behavior
with strict transition functions.

regards, tom lane