Bitwise OR

All functions > BITWISE > Bitwise OR

Returns the bitwise OR of two bitstrings or two integers.

Syntax

left | right  ·  BITWISE_OR(left, right)

Function form

Returns: Result bitstring, or NULL if either operand is NULL

BITWISE_OR(left: BITSTRING, right: BITSTRING) → BITSTRING
sql
ParameterTypeRequiredDescription
leftBITSTRINGYesLeft operand
rightBITSTRINGYesRight operand

Returns: Result integer, or NULL if either operand is NULL

BITWISE_OR(left: BIGINT, right: BIGINT) → BIGINT
sql
ParameterTypeRequiredDescription
leftBIGINTYesLeft operand (any integer type, read as 64 bits)
rightBIGINTYesRight operand (any integer type, read as 64 bits)

Notes

  • Bitstring operands must have the same length; bitstrings exist on DuckDB and Postgres only
  • Integers are 64-bit two's complement and the result is a BIGINT, on every backend
  • Each bit position is ORed independently: 0 OR 0 = 0, all other combinations = 1
  • Returns NULL if either input is NULL

Examples

BITWISE_OR(...)

FeatureQL
RETURN
    -- Complementary bits produce all 1s
    f1 := BITWISE_OR('1010'::BITSTRING, '0101'::BITSTRING)::VARCHAR,
    -- Non-overlapping bits
    f2 := BITWISE_OR('1100'::BITSTRING, '0011'::BITSTRING)::VARCHAR,
    -- OR with zero preserves bits
    f3 := BITWISE_OR('1000'::BITSTRING, '0000'::BITSTRING)::VARCHAR
;
Result
f1 VARCHARf2 VARCHARf3 VARCHAR
111111111000

Operator |

FeatureQL
RETURN
    -- Integers: 1100 OR 1010
    f1 := BITWISE_OR(12, 10)
;
Result
f1 BIGINT
14

BITWISE_OR()

FeatureQL
RETURN
    -- Complementary bits produce all 1s
    f1 := BITWISE_OR('1010'::BITSTRING, '0101'::BITSTRING)::VARCHAR
;
Result
f1 VARCHAR
1111