9.7. Bitwise Aggregate Functions

9.7.1. BIN_AND_AGG()

Bitwise AND on non-NULL values.

Result typeSame as type of expr

Syntax

BIN_AND_AGG ( <expr> )

Table 9.26. BIN_AND_AGG Function Parameters
ParameterDescription

expr

Expression of type SMALLINT, INTEGER, BIGINT, or INT128.

The result is a cumulative application of bitwise AND on all non-NULL values.

If the group is empty or contains only NULLs, the result is NULL.

9.7.1.1. BIN_AND_AGG Examples

select
  NAME,
  bin_and_agg(N) as F_AND
from ACL_MASKS
group by NAME

See alsoSection 9.7.2, “BIN_OR_AGG()”, Section 9.7.3, “BIN_XOR_AGG()”, Section 8.6.1, “BIN_AND()”

9.7.2. BIN_OR_AGG()

Bitwise OR on non-NULL values.

Result typeSame as type of expr

Syntax

BIN_OR_AGG ( <expr> )

Table 9.27. BIN_OR_AGG Function Parameters
ParameterDescription

expr

Expression of type SMALLINT, INTEGER, BIGINT, or INT128.

The result is a cumulative application of bitwise OR on all non-NULL values.

If the group is empty or contains only NULLs, the result is NULL.

9.7.2.1. BIN_OR_AGG Examples

select
  NAME,
  bin_or_agg(N) as F_OR
from ACL_MASKS
group by NAME

See alsoSection 9.7.1, “BIN_AND_AGG()”, Section 9.7.3, “BIN_XOR_AGG()”, Section 8.6.3, “BIN_OR()”

9.7.3. BIN_XOR_AGG()

Bitwise XOR on non-NULL values.

Result typeSame as type of expr

Syntax

BIN_XOR_AGG ( [ ALL | DISTINCT ] <expr> )

Table 9.28. BIN_XOR_AGG Function Parameters
ParameterDescription

expr

Expression of type SMALLINT, INTEGER, BIGINT, or INT128.

The result is a cumulative application of bitwise XOR on all non-NULL values (the default), or the distinct non-NULL values.

Contrary to Section 9.7.1, “BIN_AND_AGG()” and Section 9.7.2, “BIN_OR_AGG()”, this function accepts ALL or DISTINCT, as eliminating duplicates changes the result of the cumulative bitwise XOR. ALL is the default if nothing is specified.

If the group is empty or contains only NULLs, the result is NULL.

9.7.3.1. BIN_XOR_AGG Examples

select
  NAME,
  bin_xor_agg(N) as F_XOR,
  -- same as F_XOR
  bin_xor_agg(all N) ad F_XOR_A,
  -- might be different
  bin_xor_agg(distinct N) ad F_XOR_D
from ACL_MASKS
group by NAME

See alsoSection 9.7.1, “BIN_AND_AGG()”, Section 9.7.2, “BIN_OR_AGG()”, Section 8.6.6, “BIN_XOR()”