Documentation

    set_bit

    Sets the nth bit in bitstring to newvalue; the first (leftmost) bit is indexed 0. Returns a new bitstring.

    Try an expression

    In Formula, enter the expression and set Output type to VARCHAR.

    Expression

    set_bit('0110010'::BITSTRING, 2, 0)

    Result

    '0100010'

    The expression returns BIT. Formula stores it as VARCHAR in this example. To use your own data, replace the example values with column names. Keep format strings and other options as written.

    Arguments and types

    set_bit(bitstring, index, new_value)
    bitstring
    Bits
    index
    Number
    new_value
    Number
    Supported signatures (1)
    set_bit(bitstring: BIT, index: INTEGER, new_value: INTEGER) → BIT

    The result type can depend on the input types. See DuckDB for the full argument rules.

    Things to know

    If the first argument is missing, the result is NULL.

    Browse bitsDuckDB documentation

    Function metadata from DuckDB, used under the MIT license.