PostgreSQL将位转换为整数 [英] Postgresql Convert bit varying to integer

查看:285
本文介绍了PostgreSQL将位转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索了PostgreSQL文档 http://www.postgresql.org/ docs / 8.4 / interactive / functions-bitstring.html 有关将位转换为整数的信息

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

赞赏您的回答。

推荐答案

一种方法:

SELECT b, lpad(b::text, 32, '0')::bit(32)::int
FROM (
    VALUES
     ('01'::varbit)
    ,('011111')
    ,('111')
 ) t (b);

结果:

b      | lpad
-------+------
01     |    1
011111 |   31
111    |    7

相关答案:

  • Convert hex in text representation to decimal number

这篇关于PostgreSQL将位转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆