Re: bit strings - anyone working on them? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: bit strings - anyone working on them?
Date
Msg-id 3499.1051027684@sss.pgh.pa.us
Whole thread Raw
In response to Re: bit strings - anyone working on them?  (Philip Warner <pjw@rhyme.com.au>)
Responses Re: bit strings - anyone working on them?  (Philip Warner <pjw@rhyme.com.au>)
List pgsql-hackers
Philip Warner <pjw@rhyme.com.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



pgsql-hackers by date:

Previous
From: Philip Warner
Date:
Subject: Re: bit strings - anyone working on them?
Next
From: Philip Warner
Date:
Subject: Re: bit strings - anyone working on them?