ANY_VALUE() OVER ...

All functions > WINDOW FUNCTION > ANY_VALUE() OVER ...

Returns a non-null value of the window frame: the minimum in value order, NULL if there is none.

Syntax

ANY_VALUE(expr) [FILTER (WHERE condition) | WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])

Notes

  • Deterministic: the result is MIN() of the frame (NULLs skipped), the same on every run and every backend
  • When PARTITION BY determines the value (one value per partition), the native ANY_VALUE is emitted: it returns that value without comparing
  • With ORDER BY, the default frame ends at the current row: the result is the running minimum
  • EXPLAIN (FIELDS (OPTIMIZATIONS)) records the choice as any_value_native
  • Returns same type as input expression

See also

Examples

FeatureQL
-- The minimum of the frame so far, in id order
-- The running minimum of the rows where v > 15 (10 and 5 excluded from the frame)
RETURN
    f1 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        RETURN ANY_VALUE(v) OVER (ORDER BY id ASC)
    ).UNWRAP(),
    f2 := ZIP(ARRAY(1, 2, 3, 4) AS id, ARRAY(30, 10, 20, 5) AS v).TRANSFORM(
        RETURN ANY_VALUE(v) FILTER (WHERE v > 15) OVER (ORDER BY id ASC)
    ).UNWRAP()
;
Result
f1 ARRAY<BIGINT>f2 ARRAY<BIGINT>
[30, 10, 10, 5][30, 30, 20, 20]