Subject RE: [IB-Architect] Aggregate functions request - FIRST() & LAST()
Author Slavomir Skopalik
I think about User Definned Agregate Function (UDAF) like UDF.
I'm of opinion that First() and Last() is too specific.

What do you think about UDAF ?
My idea is:
one UDAF will be defined as following set of
functions (like UDF).

1. int CreateHandle();
2. bool AddElement(int handle, etype element1, etype element2, ... ); /* succes true else false */
3. etype Compute(int handle,etype param1, etype param2);
4. void FreeHandle(int handle);

SQL syntax UDAFName(element1,element2,...,param1,param2,...)

where etype can be any basic interbase type (integers, floats, datetimes, chars,...),
params for parametrization of Compute function like this:

select MySum(field,2) from table;
where field is table field and 2 maybe statistical moment or any other parameter.

If you want eliminate set of functions, this can be realizad by this way:

One function with this interface:

int UDAFName(int command, int handle, *etype element1, *etype element2, ...);

where
command tell what woudl be do, handle is valid handle or zero.
command value is like the set of function definition:
1=CreateHandle, handle is zero, return is handle or zero
2=Add elements, return 1 for true, 0 for false
3=Compute result, result is in element1, or return like pointer to result (after type cast)
4=FreeHandle.

For what be used ?
- statistical computing (median, non normal distribution function mean,...)
- Integrations (simpson rule, ...)
- any special aggregate functions

Slavek