Re: bit strings - anyone working on them?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: bit strings - anyone working on them?
Date: 2003-04-22 16:08:04
Message-ID: 3499.1051027684@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Philip Warner <pjw(at)rhyme(dot)com(dot)au> writes:
> At least in 7.3.2 we can't cast int to varbit. Worse still (and maybe I am
> missing something):

> # select cast(8 as bit(10));
> bit
> ------------
> 0000000000

Not sure we have a lot of choice there. The basic cast is to bit(32).
We have

regression=# select cast(8 as bit(32));
bit
----------------------------------
00000000000000000000000000001000
(1 row)

regression=# select cast(8 as bit(32)) :: bit(10);
bit
------------
0000000000
(1 row)

If you make the direct cast do something different, it'll be
inconsistent.

What is perhaps needed is a bitstring length adjustment operation that
allows padding or truncation to occur at the left instead of the right.
The semantics of cast are already spoken for, but we could provide this
as a function.

As for int->varbit, you can get there easily enough:

regression=# select cast(8 as bit(32)) :: varbit;
varbit
----------------------------------
00000000000000000000000000001000
(1 row)

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Philip Warner 2003-04-22 16:19:31 Re: bit strings - anyone working on them?
Previous Message Philip Warner 2003-04-22 15:51:56 Re: bit strings - anyone working on them?