org.h2.api

## Interface AggregateFunction

-     public interface AggregateFunction

  A user-defined aggregate function needs to implement this interface. The class must be public and must have a public non-argument constructor.

  Please note this interface only has limited support for data types. If you need data types that don't have a corresponding SQL type (for example GEOMETRY), then use the `Aggregate` interface.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(java.lang.Object value)` This method is called once for each row.
    `java.lang.Object` | `getResult()` This method returns the computed aggregate value.
    `int` | `getType(int[] inputTypes)` This method must return the SQL type of the method, given the SQL type of the input data.
    `default void` | `init(java.sql.Connection conn)` This method is called when the aggregate function is used.

- - ### Method Detail

    - #### init

          default void init(java.sql.Connection conn)
                     throws java.sql.SQLException

      This method is called when the aggregate function is used. A new object is created for each invocation.
      Parameters:
        `conn` - a connection to the database
      Throws:
        `java.sql.SQLException` - on SQL exception

    - #### getType

          int getType(int[] inputTypes)
               throws java.sql.SQLException

      This method must return the SQL type of the method, given the SQL type of the input data. The method should check here if the number of parameters passed is correct, and if not it should throw an exception.
      Parameters:
        `inputTypes` - the SQL type of the parameters, `Types`
      Returns:
        the SQL type of the result
      Throws:
        `java.sql.SQLException` - on failure

    - #### add

          void add(java.lang.Object value)
            throws java.sql.SQLException

      This method is called once for each row. If the aggregate function is called with multiple parameters, those are passed as array.
      Parameters:
        `value` - the value(s) for this row
      Throws:
        `java.sql.SQLException` - on failure

    - #### getResult

          java.lang.Object getResult()
                              throws java.sql.SQLException

      This method returns the computed aggregate value. This method must preserve previously added values and must be able to reevaluate result if more values were added since its previous invocation.
      Returns:
        the aggregated value
      Throws:
        `java.sql.SQLException` - on failure