BIT_XOR() OVER ...

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

Returns the bitwise XOR of integer values in the window frame.

Syntax

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

Notes

  • SQL translation is implemented only when the current SQL backend is DuckDB
  • Requires a well-defined window (ORDER BY, and optionally PARTITION BY and frame)
  • NULL values are ignored where the underlying window aggregate skips NULLs
  • Argument type must be an integer type

Availability

Available on DuckDB. Not available on Trino, Serving.

See also

Examples

FeatureQL
-- Running bitwise XOR
-- Running bitwise XOR counting only 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,
        ARRAY(3, 5, 6, 7) AS x
    ).TRANSFORM(RETURN BIT_XOR(x) OVER (ORDER BY id ASC)).UNWRAP(),
    f2 := ZIP(
        ARRAY(1, 2, 3, 4) AS id,
        ARRAY(30, 10, 20, 5) AS v,
        ARRAY(3, 5, 6, 7) AS x
    ).TRANSFORM(RETURN BIT_XOR(x) FILTER (WHERE v > 15) OVER (ORDER BY id ASC)).UNWRAP()
;
Result
f1 ARRAY<BIGINT>f2 ARRAY<BIGINT>
[3, 6, 0, 7][3, 3, 5, 5]