Re: Inconsistent ::bit(N) and get_bit()?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Boszormenyi Zoltan <zb(at)cybertec(dot)at>, PGSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Inconsistent ::bit(N) and get_bit()?
Date: 2010-08-15 21:29:48
Message-ID: 5725.1281907788@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> 2010/8/11 Boszormenyi Zoltan <zb(at)cybertec(dot)at>:
>> Shouldn't it at least be documented in more depth? Say, get_bit(, N)
>> provides the Nth bit (0-based) counting from the leftmost bit?
>> I would certainly appreciate a warning spelled out about this
>> so if you convert a number to bitstring of length N and you want the
>> Mth bit (according to any programming language) then you need to use
>> get_bit(..., N-1-M).

> The fact that bit-strings subscript from the left rather than from the
> right seems pretty odd to me, but it is documented.

It's not odd if you think of them as strings, rather than some weird
representation of an integer.

> I wouldn't object
> to adding a note to somewhere around here, if we can think of a
> suitable way to word it:
> http://www.postgresql.org/docs/9.0/static/functions-bitstring.html

Yeah, it really needed something, especially since the docs presented
get_bit/set_bit as being not interestingly different from the bytea
versions. (They do act the same at the physical level, but because the
I/O representation of bit and bytea is so different, I think they have
to be described differently.) I committed some additional text for
this.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-08-15 21:39:08 Re: DropRelFileNodeBuffers API change (was Re: [BUGS] BUG #5599: Vacuum fails due to index corruption issues)
Previous Message Greg Stark 2010-08-15 21:17:54 Re: DropRelFileNodeBuffers API change (was Re: [BUGS] BUG #5599: Vacuum fails due to index corruption issues)