From: Tom Lane <tgl@sss.pgh.pa.us>
To: Francisco Olarte <folarte@peoplecall.com>
Cc: amovitz@bncpu.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #16403: set_bit function does not have expected effect
Date: Thu, 30 Apr 2020 09:57:46 -0400
Message-ID: <20591.1588255066@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+bJJbzyLq9wHynta=NFR2gWOq3ZdJY1frBoCqNjr76+HupVMA@mail.gmail.com>
References: <16403-c4ad1c176b130a5b@postgresql.org>
<CA+bJJbzyLq9wHynta=NFR2gWOq3ZdJY1frBoCqNjr76+HupVMA@mail.gmail.com>
Francisco Olarte <folarte@peoplecall.com> writes:
> On Thu, Apr 30, 2020 at 9:47 AM PG Bug reporting form
> <noreply@postgresql.org> wrote:
>> set_bit function changes the right-most bit of the byte, but with
>> little-endian byte order. This is confusing to any use case where setting a
>> bit in a BYTEA in a specific position. To iterate through the bits within
>> the BYTEA, one must have nested loops which set bits within byte boundaries.
> I think this is a display expectations issue, when using addresses it
> seems it is changing the least significant bit in the first byte and
> the second byte ( in C-speak it is setting bit n%8 byte n/8 ),
Yeah, the documentation is quite clear about this:
Functions get_byte and set_byte number the first byte of a binary
string as byte 0. Functions get_bit and set_bit number bits from the
right within each byte; for example bit 0 is the least significant bit
of the first byte, and bit 15 is the most significant bit of the
second byte.
so we're not likely to change it.
You might consider using type "bit" instead of bytea, since the bit
display order is more closely tied to how set_bit() numbers the bits.
Another option is to write your own functions that number the bits
however you want.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, folarte@peoplecall.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16403: set_bit function does not have expected effect
In-Reply-To: <20591.1588255066@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox