SLOPDB / DOCUMENTATION / WINDOW FUNCTION REFERENCE
Window function reference
Function inventory verified against the supplied SlopDB source checkout e5e2eb2. Entries document implemented behavior, including compatibility placeholders and restrictions.
Window functions retain source rows and run after grouping/HAVING, before the final ORDER BY/LIMIT. They can appear in SELECT and ORDER BY. Use a CTE or derived table to filter their results. See the window guide for full frame syntax, named windows, limits, and execution behavior.
Frames and peers
ROWS, RANGE, and GROUPS frames are supported. With ORDER BY, the default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, including peers. Without ORDER BY, it is the whole partition. Value functions respect the frame; ranking and LAG/LEAD ignore it. Offset/position values must fit the documented int64 limits.
Aggregate windows are COUNT, SUM, AVG, MIN, and MAX; they are described in the aggregate reference. PERCENT_RANK, CUME_DIST, NTILE, FILTER, EXCLUDE, and DISTINCT window aggregates are unsupported. Windows materialize within the query memory budget and do not spill to disk.
Ranking and navigation
DENSE_RANK() OVER (window)
Returns INTEGER
Ranks peer groups without gaps. Ranking ignores the frame.
SELECT v, DENSE_RANK() OVER (ORDER BY v) AS n FROM (SELECT 1 AS v UNION ALL SELECT 2) AS sample;
Source: sql/window_execution.go · e5e2eb2
FIRST_VALUE(value) OVER (window)
Returns value type
Returns the value from the first/last row of the current frame, not necessarily the full partition. An empty frame returns NULL.
SELECT v, FIRST_VALUE(v) OVER (ORDER BY v ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS edge FROM (SELECT 1 AS v UNION ALL SELECT 2) AS sample;
Source: sql/window_execution.go · e5e2eb2
LAG(value [, offset [, default]]) OVER (window)
Returns value type
Reads a preceding/following row, default offset one. Offsets must be nonnegative int64. Missing rows use default (NULL when omitted); NULL input values are preserved. The frame is ignored.
SELECT v, LAG(v, 1, 0) OVER (ORDER BY v) AS other FROM (SELECT 1 AS v UNION ALL SELECT 2) AS sample;
Source: sql/window_execution.go · e5e2eb2
LAST_VALUE(value) OVER (window)
Returns value type
Returns the value from the first/last row of the current frame, not necessarily the full partition. An empty frame returns NULL.
SELECT v, LAST_VALUE(v) OVER (ORDER BY v ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS edge FROM (SELECT 1 AS v UNION ALL SELECT 2) AS sample;
Source: sql/window_execution.go · e5e2eb2
LEAD(value [, offset [, default]]) OVER (window)
Returns value type
Reads a preceding/following row, default offset one. Offsets must be nonnegative int64. Missing rows use default (NULL when omitted); NULL input values are preserved. The frame is ignored.
SELECT v, LEAD(v, 1, 0) OVER (ORDER BY v) AS other FROM (SELECT 1 AS v UNION ALL SELECT 2) AS sample;
Source: sql/window_execution.go · e5e2eb2
NTH_VALUE(value, position) OVER (window)
Returns value type
Returns a one-based positive int64 position within the current frame. Returns NULL when the frame is empty or has too few rows.
SELECT v, NTH_VALUE(v, 2) OVER (ORDER BY v ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS second FROM (SELECT 1 AS v UNION ALL SELECT 2) AS sample;
Source: sql/window_execution.go · e5e2eb2
RANK() OVER (window)
Returns INTEGER
Ranks peer groups with gaps after ties. Ranking ignores the frame.
SELECT v, RANK() OVER (ORDER BY v) AS n FROM (SELECT 1 AS v UNION ALL SELECT 2) AS sample;
Source: sql/window_execution.go · e5e2eb2
ROW_NUMBER() OVER (window)
Returns INTEGER
Assigns consecutive row numbers within each partition. Add a unique ORDER BY to make numbering deterministic among peers.
SELECT v, ROW_NUMBER() OVER (ORDER BY v) AS n FROM (SELECT 1 AS v UNION ALL SELECT 2) AS sample;