SQL-J Language Reference
Page 88 of 121

User-Defined Aggregate

Cloudscape allows you to create your own aggregate functions. After you create the Java classes that implement the aggregation and create the aggregate with the CREATE AGGREGATE statement, you can use those aggregate from within SQL-J the same way you use the built-in aggregates.

The resulting data type of the user-defined aggregate function is defined by the implementing class. If you provide the correct implementation, a user-defined aggregate can return any built-in type or any user-defined Java data type.

For information about creating the Java classes that implement the aggregation, see Programming User-Defined Aggregates in the Cloudscape Developer's Guide.

Syntax

AggregateName ( [ DISTINCT | ALL ] Expression )

User-Defined Aggregate Examples

-- MAXBUTONE is a user-defined aggregate
SELECT MAXBUTONE(DISTINCT miles)
FROM Flights

SELECT STDEV(flying_time)
FROM Flights