Re: problem with bit(n) type

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: problem with bit(n) type
Дата
Msg-id 20051012134339.GD20074@svana.org
обсуждение исходный текст
Ответ на problem with bit(n) type  (Sergey Karin <sergey.karin@gmail.com>)
Список 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@svana.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.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Lincoln Yeoh
Дата:
Сообщение: Re: Row level locking
Следующее
От: Ron Mayer
Дата:
Сообщение: Re: PostgreSQL 8.1 vs. MySQL 5.0?