lag
lag(value: storable, lagby: const int64) -> value
lag(value, lagby) returns the value expression evaluated on the row found lagby physical rows earlier in the current window partition order, where lagby is a non-negative compile-time integer constant. lag(0) is the current row value. If there is no such prior row inside the frame the result is null. The function is only valid inside window with explicit grouping and ordering; null entries in value still occupy row positions when counting backward unless you use lag_not_null instead.
Domain
This is a window function (calculates over a group of multiple input rows using windowing).
Categories
Examples
make_col prev:window(lag(status, 1), group_by(host), order_by(valid_from))
Pulls the previous row status value one step back in valid_from order for each host.
make_col prev2:window(lag(cpu_pct, 2), group_by(instance), order_by(valid_from), frame(back:1h))
Uses lag with offset two inside an explicit one-hour frame so earlier spikes can be compared on the same instance.
Updated 19 days ago