Skip to main content
Returns the value of an expression evaluated at the Nth row of the window frame. Returns NULL if the frame contains fewer than N rows. For more information on usage, please refer to Window Functions.

Syntax

Parameters

ParameterDescriptionSupported input types
<expression>The value to evaluate and return at position N in the window frame.Any
<n>The 1-based position within the window frame. Must be a positive integer.INTEGER, BIGINT
<partition_by>An expression used for the PARTITION BY clause.Any
<order_by>An expression used for the ORDER BY clause.Any
<frame_clause>An optional window frame specification such as ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.

Return Type

Same as the input type of <expression>.

Remarks

  • <n> must be greater than or equal to 1. Passing 0 or a negative value raises an error.
  • Returns NULL when N exceeds the number of rows in the window frame.
  • This function respects NULL values, and results will be ordered with default null ordering NULLS LAST unless otherwise specified in the ORDER BY clause.

Example

The following example returns the second-lowest maxpoints value within each leveltype, repeated for every row in that group:
level int nullleveltype text nullmaxpoints int nullsecond_lowest int null
6Drift80250
9Drift250250
1FastestLap2040
3FastestLap4040
7FastestLap7040
8FastestLap10040
2FirstToComplete30100
4FirstToComplete100100
5FirstToComplete150100
10FirstToComplete500100

Rows: 10Execution time: 11.07ms