Skip to content
masterclass Buddy

PostgreSQL · Function

lag

LAG returns a value from an earlier row in the same window partition. It is useful for comparing each row with a previous row.

Last updated

Syntax

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

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • lead
  • first_value
  • last_value
  • nth_value

Source: PostgreSQL: Documentation: 18: 9.22. Window Functions. Checked 2026-11-03.