Return the bitwise OR of two integer values.
BIT_OR(a, b)
## Overview Returns an integer whose bits are the bitwise OR of the corresponding bits in the two operands. A bit in the result is 1 if the bit at the same position is 1 in either input. Use this function to set feature bits, merge permission masks, or union two bitmaps. BIT_OR is the function form of the `|` operator and pairs naturally with BIT_AND and BIT_NOT for flag manipulation in generated SQL and analytics pipelines. ## Behavior - Returns NULL if either argument is NULL. - Operates on the two's complement bit pattern of the integers. - Both arguments are promoted to the widest integer type among the two before the operation. - Result is deterministic and side effect free. - BIT_OR(x, x) equals x. BIT_OR(x, 0) equals x. BIT_OR(x, -1) equals -1 (all bits on). ## Bit semantics - Bits are numbered from 0 at the least significant end. - To set bit n in a value, OR with `1 << n`: `BIT_OR(x, 1 << n)`. - Multiple feature bits can be set in one expression: `BIT_OR(BIT_OR(x, 1), 4)` sets bits 0 and 2. ## Compatibility - Equivalent to the standard `|` operator and to the PG-compat function of the same name.
| Name | Type | Description |
|---|---|---|
a | Specifies the first integer operand. Treated as a two's complement signed value across the full width of the argument type. | |
b | Specifies the second integer operand. Must be the same integer width as the first operand after implicit promotion. |
-- Basic bitwise OR of 12 (1100) and 10 (1010)
SELECT BIT_OR(12, 10); -- 14
-- OR with zero returns the original value
SELECT BIT_OR(42, 0); -- 42
-- Combining two flag sets
SELECT BIT_OR(3, 12) AS combined_flags; -- 15
-- Set a specific feature bit (bit 3) on every account
SELECT account_id, BIT_OR(feature_flags, 8) AS updated_flags
FROM security.catalog.accounts;
-- Merge permission masks across roles in a user-role join
SELECT user_id, BIT_OR(role_mask, extra_mask) AS effective_mask
FROM security.catalog.user_roles;
-- NULL propagation
SELECT BIT_OR(5, NULL); -- NULL