Choose the operator function
The SUM built-in aggregate function uses the plus operator (+), which the plus() user-defined function implements. The database server provides implementations of the plus() function over the built-in data types. Therefore, the SUM aggregate function works over built-in data types. To have the SUM aggregate operate on the complexnum_t row type, you implement a plus() function that handles this named row type; that is, it adds the two parts of the complex number and returns a complex number with the summed parts.
The following C function, complex_plus(),
defines such a plus() function:
MI_ROW *complex_plus(arg1, arg2)
MI_ROW *arg1;
MI_ROW *arg2;