Postgresql Convert bit varying to integer
问题 Searched the postgresql docs http://www.postgresql.org/docs/8.4/interactive/functions-bitstring.html for information on converting bit varying to integer But couldnt' find any info. select '011111'::bit(4)::varbit(4)::integer as varbit Appreciate your response. 回答1: One way: SELECT b, lpad(b::text, 32, '0')::bit(32)::int FROM ( VALUES ('01'::varbit) ,('011111') ,('111') ) t (b); Result: b | lpad -------+------ 01 | 1 011111 | 31 111 | 7 Related answer: Convert hex in text representation to