You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is already supported in Oracle. Many other databases also support custom aggregate functions, among which HSQLDB. An example:
CREATEAGGREGATEFUNCTION second_max(
IN val INTEGER,
IN flag BOOLEAN,
INOUT highest INTEGER,
INOUT second_highest INTEGER
)
RETURNS INTEGER
CONTAINS SQL
BEGIN ATOMIC
DECLARE temp INTEGER;
IF flag THEN
RETURN second_highest;
ELSE
SET temp = highest;
SET highest = GREATEST(COALESCE(highest, -2147483648), val);
SET second_highest = CASE WHEN temp < highest THEN temp ELSE second_highest END;
SET temp = GREATEST(COALESCE(second_highest, -2147483648), val);
SET second_highest = CASE WHEN temp < highest THEN temp ELSE second_highest END;
END IF;
END
This is already supported in Oracle. Many other databases also support custom aggregate functions, among which HSQLDB. An example:
This can then be used as such:
As documented here:
http://hsqldb.org/doc/guide/sqlroutines-chapt.html#src_aggregate_functions
The text was updated successfully, but these errors were encountered: