From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | Sergey Karin <sergey(dot)karin(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: problem with bit(n) type |
Date: | 2005-10-12 13:43:39 |
Message-ID: | 20051012134339.GD20074@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Oct 12, 2005 at 12:24:41PM +0400, Sergey Karin wrote:
> But if I do something like this:
> kosten=# select t::text from foo;
> ERROR: cannot cast type bit to text
>
> I get an error. Okay the system cannot cast bit to text...
> But this is the big problem for me... Is there a way to cast bit(n) to
> text or varchar?
You found the conversion functions, and you can use them to work around
this like follows:
test=# select textin(bit_out(b'1010'));
textin
--------
1010
(1 row)
So perhaps:
test=# create function bit_to_text (bit) returns text
as 'select textin(bit_out($1))' language sql strict immutable;
CREATE FUNCTION
test=# select substr( bit_to_text( b'10110001' ), 3, 3 );
substr
--------
110
(1 row)
Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
From | Date | Subject | |
---|---|---|---|
Next Message | Ron Mayer | 2005-10-12 13:55:56 | Re: PostgreSQL 8.1 vs. MySQL 5.0? |
Previous Message | Lincoln Yeoh | 2005-10-12 13:30:50 | Re: Row level locking |