Let's say our table has 3 columns and 3 rows. We can simulate it with:
select *
from (
values ('row1', 1::int, 12::bit(8)::varbit),
('row2', 2::int, 23::bit(8)::varbit),
('row3', 3::int, 34::bit(8)::varbit)
) as T(A,B,C);
As you can see, first columns is varchar
, second is int
and the third is varbit
.
Let's convert third column to int
:
select C::bit(8)::int
from (
values ('row1', 1::int, 12::bit(8)::varbit),
('row2', 2::int, 23::bit(8)::varbit),
('row3', 3::int, 34::bit(8)::varbit)
) as T(A,B,C);
==C==
12
23
34
The point is, you have to convert it to bit(n)
first, then you can convert bit(n)
to varbit
. The same thing is also true for int
to varbit
.