CREATE AGGREGATE state function with one argument

Started by Thalis A. Kalfigopoulosalmost 25 years ago2 messagesgeneral
Jump to latest
#1Thalis A. Kalfigopoulos
thalis@cs.pitt.edu

In the manual fro creating aggregate functions (http://www.postgresql.org/idocs/index.php?sql-createaggregate.html) it reads:

sfunc

The name of the state transition function to be called for each input data value. This is normally a function of two arguments, the first being of type state_type and the second of type input_data_type. --->Alternatively, for an aggregate that does not examine its input values, the function takes just one argument of type state_type<---. In either case the function must return a value of type state_type. This function takes the current state value and the current input data item, and returns the next state value.

So I try this:

thalis=# CREATE FUNCTION state_func(int4) RETURNS int4 AS 'SELECT $1;' LANGUAGE 'sql';
CREATE
thalis=# CREATE AGGREGATE myaggr (basetype=int4,sfunc=state_func,stype=int4);
ERROR: AggregateCreate: function 'state_func(int4, int4)' does not exist

I understand that I can have a state function that takes just one argument. Missing smthng?

TIA,
thalis

ps running 7.1.1

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thalis A. Kalfigopoulos (#1)
Re: CREATE AGGREGATE state function with one argument

"Thalis A. Kalfigopoulos" <thalis@cs.pitt.edu> writes:

In the manual fro creating aggregate functions (http://www.postgresql.org/idocs/index.php?sql-createaggregate.html) it reads:
--->Alternatively, for an aggregate that does not examine its input
values, the function takes just one argument of type
state_type<---.

Yup. It also says

input_data_type

The input data type on which this aggregate function operates. This
can be specified as ANY for an aggregate that
does not examine its input values (an example is count(*)).

Perhaps "can" is the wrong word there, you *must* say ANY if your
aggregate is input-value-independent.

regards, tom lane