select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / BINARY STRING FUNCTIONS AND OPERATORS

Sets n'th bit in binary string to newvalue.

Signatures & examples

set_bit ( bytes bytea, n bigint, newvalue integer ) → bytea
Sets n'th bit in binary string to newvalue.
set_bit('\x1234567890'::bytea, 30, 0) → \x1234563890
set_bit ( bits bit, n integer, newvalue integer ) → bit
Sets n'th bit in bit string to newvalue; the first (leftmost) bit is bit 0.
set_bit(B'101010101010101010', 6, 0) → 101010001010101010
Version history 1
  1. PG 12 → 13changed

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source