Scalar function
Aliases: bitwise_and
Returns NULL when either operand is NULL. A NULL padside argument is rejected.
Syntax
Integers or binary values
- For BINARY inputs, both byte sequences must have the same length.
Binary values with padding
- Zero-pad the shorter byte sequence to match the longer one.
Alias: BITWISE_AND (numeric values only)
- Takes exactly two numeric operands. Integer operands use a common integer type. Other numeric operands are converted to BIGINT and must fit that type.
- BITWISE_AND does not accept BINARY inputs or a padside argument.
Arguments
Integer, bitwise and integer
Binary
Binary padding
Bitwise and numeric cast
Returns
- Type: TINYINT, SMALLINT, INTEGER or BIGINT for integer operands (the wider input type); BINARY for binary operands
- Possible values: Each output bit is 1 only when both corresponding input bits are 1.
- NULL behavior: Returns NULL when either operand is NULL. A NULL padside argument is rejected.
Binary, Binary padding
- Type: BINARY
- Possible values: Each output bit is 1 only when both corresponding input bits are 1.
- NULL behavior: Returns NULL when either binary operand is NULL.
Bitwise and integer
- Type: TINYINT, SMALLINT, INTEGER or BIGINT: the wider signed integer input type
- Possible values: Each output bit is 1 only when both corresponding input bits are 1.
- NULL behavior: Returns NULL when either integer operand is NULL.
Bitwise and numeric cast
- Type: BIGINT when at least one operand is a noninteger numeric value
- Possible values: The bitwise AND of the converted signed BIGINT operands.
- NULL behavior: NULL numeric inputs remain NULL through conversion and produce NULL.
Properties
Usage notes
- Binary operands of unequal lengths require a padside argument. Zero bytes are added on the requested side of the shorter operand.
- Integer operands are converted to a common integer type. BITWISE_AND also converts noninteger numeric inputs to BIGINT; BITAND does not accept those inputs.
- INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
Examples
Integer AND
Example values
Limitations
- Without padside, unequal binary lengths raise an execution error.
- padside must be a string literal LEFT or RIGHT (case-insensitive); NULL, arbitrary expressions and other strings are rejected.
- BITWISE_AND converts noninteger numeric operands to BIGINT before the bitwise operation. Values that cannot be converted can raise an error. Query tools may report the first argument’s type even when the result is BIGINT.
Last modified on October 15, 2026