Thread: Urgent help in bit_string data type

Urgent help in bit_string data type

From
Karthikeyan Sundaram
Date:

Hi Gurus,
 
   I have a table with datatype as bitstrings
 
 
create table test_a (b bit(3));
 
insert into test_a values ('111');

This will convert a bit to a number
==========================
select to_number((substring(b,1,1)::int),9)+3 from test_a;

How will I convert a Number to a bit
----------------------------------
 
insert into test_a values (to_char(1,'9'));
 
ERROR:  column "b" is of type bit but expression is of type text
HINT:  You will need to rewrite or cast the expression.
 
Please help me
 
regards
skarthi
 


i'm making a difference. Make every IM count for the cause of your choice. Join Now.

Re: Urgent help in bit_string data type

From
Joe
Date:
Hi skarthi,

On Wed, 2007-04-11 at 13:30 -0700, Karthikeyan Sundaram wrote:
>         insert into test_a values (to_char(1,'9'));
>
>         ERROR:  column "b" is of type bit but expression is of type
>         text
>         HINT:  You will need to rewrite or cast the expression.

As suggested by the error, you should use a cast, e.g.,

    insert into test_a values 9::bit(3);

This will result in binary '001' being inserted because you need 4 bits
to represent decimal 9.

Joe