last_value aggregate function

Returns the last value of expr for the group of rows.

Syntax

last_value(expr [, ignoreNull] ) [FILTER ( WHERE cond ) ] [ IGNORE NULLS | RESPECT NULLS ]

Arguments

  • expr: An expression of any type.

  • ignoreNull: A optional BOOLEAN literal

  • cond: An optional boolean expression filtering the rows used for aggregation.

  • IGNORE NULLS or RESPECT NULLS: When IGNORE NULLS is used or ignoreNull is true any expr value that is NULL is ignored. The default is RESPECT NULLS.

Returns

The result type matches expr.

The function is a synonym for last aggregate function.

This function is non-deterministic.

Examples

> SELECT last_value(col) FROM VALUES (10), (5), (20) AS tab(col);
 20
> SELECT last_value(col) FROM VALUES (10), (5), (NULL) AS tab(col);
 NULL
> SELECT last_value(col) IGNORE NULLS FROM VALUES (10), (5), (NULL) AS tab(col);
 5