lead()

Returns value evaluated at the row that is offset rows after the current row within the partition; if there is no such row, instead returns default (which must be of a type compatible with value). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to NULL.

Signature

lead ( value anycompatible [, offset integer [, default anycompatible ]] ) → anycompatible

Examples

SELECT product, amount, lead(amount) OVER (ORDER BY id) FROM orders;
 product  | amount |  lead  
----------+--------+--------
 keyboard |  49.50 | 219.00
 monitor  | 219.00 |  99.00
 keyboard |  99.00 |  27.75
 mouse    |  27.75 | 438.00
 monitor  | 438.00 |  15.00
 cable    |  15.00 |   NULL
(6 rows)

Run against PostgreSQL 18.6 on 2026-09-13. This is the output we got, not the documentation’s.

Want to run this against your own PostgreSQL server from an iPhone, iPad or Mac? These are ours — every connection goes straight from the device to your database, with no account and no server of ours in between.

Signature and description adapted from the PostgreSQL manual, used under the PostgreSQL License. PostgreSQL is a registered trademark of the PostgreSQL Community Association of Canada. This page is not affiliated with the PostgreSQL Global Development Group.