PREV()

Other. Returns the value of a given column from a prior row.

Syntax

PREV( column [, offset]) GETTIMESTAMP(PREV( name ))
Parameters

column

The name of a column of any type.

offset

Which row to use, with 0 as the current row, 1 as the immediately previous row, and so on. If omitted, defaults to1.

name

The name of a stream or window.

Data Types

Return

column

offset

The same type as the specified column.

String

Integer

Return

name

Timestamp

String

Usage

When you use PREV() on a data source grouped with GROUP BY or PER, offset refers to a previous row within the same group as the newly arrived row.

PREV embedded in GETTIMESTAMP returns the timestamp of the previous row in the specified stream or window.

You can use PREV() in a WHERE selection condition or a SELECT clause select list.

When you use PREV() on data streams, it is semantically identical to the [ ] row operator.

Example

The following example returns the value of the Price column from the row two previous to the current row:

INSERT INTO OutStream
SELECT PREV(Trades.Price, 2)
FROM Trades;