Search Postgresql Archives

Re: problem with bit(n) type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>   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.

Attachment: pgpg4cHtmERxM.pgp
Description: PGP signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux