BITWISE_XOR_AGG

Updated at:

Calculates the aggregate value of the input value using the BIT XOR operation.

Syntax

BIGINT BITWISE_XOR_AGG([DISTINCT] BIGINT|INT|SMALLINT|TINYINT value)

Parameters

  • DISTINCT: Optional. If you specify DISTINCT, each distinct value is aggregated only once in the result.

  • value: Required. A value of BIGINT, INT, SMALLINT, or TINYINT type. NULL values are not included in the calculation.

Return value

Returns a BIGINT value, which is the result of performing the BIT XOR operation on all input values.

  • If the value is not of BIGINT, INT, SMALLINT, or TINYINT type, an error is returned.

  • If the value is NULL, NULL is returned.

Examples

-- Example 1 
SELECT id, BITWISE_XOR_AGG(v) FROM 
  VALUES (1L, 2L), (1L, 1L), (2L, NULL), (1L, NULL) t(id, v) GROUP BY id;
-- Result
+------------+------------+
| id         | _c1        | 
+------------+------------+
| 1          | 3          | 
| 2          | NULL       | 
+------------+------------+

-- Example 2 
SELECT id, BITWISE_XOR_AGG(DISTINCT v) FROM   
  VALUES (1L, 2L), (1L, 1L), (1L, 1L), (2L, NULL), (1L, NULL) t(id, v) GROUP BY id;
-- Result
+------------+------------+
| id         | _c1        | 
+------------+------------+
| 1          | 3          | 
| 2          | NULL       | 
+------------+------------+