valueinserted()

Aggregate. Returns a value from a group, based on the last row applied into that group. Returned values include NULLS.

Syntax

valueinserted ( expression )

Parameters

expression

The expression accepts all datatypes.

Usage

Returns the value of the expression computed using the most recent event used to insert/update the group. If the current event removes a row from the group then it returns a NULL.

This function is considered an additive function. Using only additive functions in the projection of a SELECT statement allows the server to optimize the aggregation, which results in greater throughput and lower memory utilization.

Example

The following is an aggragate that outputs the minimum, maximum, average, and last value of the rows read from inWin, grouped by symbol. The last value is called by using the valueinserted() function.
 CREATE INPUT WINDOW inWin SCHEMA  ( id long, symbol string, value money(2) ) PRIMARY KEY ( id ) KEEP 5 MINUTES;

 CREATE OUTPUT WINDOW stats PRIMARY KEY DEDUCED KEEP 5 MINUTES  AS
 SELECT i.symbol,
        min(i.value) minValue,
        max(i.value) maxValue,
        avg(i.value) avgValue,   
        valueInserted(i.value) lastValue    
 FROM inWin i GROUP BY i.symbol;