Skip to main content

last function for MATCH_RECOGNIZE

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 19.0 and above

Beta

This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Databricks previews.

Returns a column value relative to the last row in the match. When you use last in the DEFINE clause, the last row is the current row. Use this function only in the MEASURES and DEFINE clauses of MATCH_RECOGNIZE.

For the generic last aggregate function, see last.

Syntax

last ( { colName | rowPatternVar.colName } [, offset ] )

Arguments

  • colName: A column from the table_reference that MATCH_RECOGNIZE operates on.
  • rowPatternVar.colName: A column qualified by a row pattern variable name. Reads the column value from rows mapped to that variable in the current match. For example, LAST(down.tstamp) returns the timestamp of the last row classified as down.
  • offset: An optional integral literal greater than or equal to 0. The offset relative to the last row. The default is 0.

Returns

A value of the type of colName. If the identified row is outside the current partition, returns NULL.

Common error conditions