Skip to content

bit_and ​

Applies bitwise AND to a sequence of integer values. NULL inputs are skipped.

Syntax

text
bit_and(value)

Arguments

  • value — An exact signed or unsigned integer, including native widths through 256 bits. Floating-point values, decimals and text raise TYPE_MISMATCH.

Returned value

The exact integer formed by applying AND to every admitted value. A declared integer width is retained; mixed runtime integer classes widen within native bounds. A result outside the supported native range raises NUMERIC_OVERFLOW.

An empty input, or an input containing only NULL, returns NULL.

Examples

Combining bit masks

In binary, 1100 AND 1010 = 1000:

sql
CREATE TABLE masks (value INTEGER);
INSERT INTO masks VALUES (12), (10), (NULL);
sql
SELECT bit_and(value) AS combined_mask
FROM masks
FORMAT csv;
text
8

No non-NULL masks

sql
CREATE TABLE null_masks (value INTEGER);
INSERT INTO null_masks VALUES (NULL), (NULL);
sql
SELECT bit_and(value)
FROM null_masks
FORMAT csv;
text
\N

See bit functions for scalar bit operations.