get_bit() 是一个用于从二进制字符串中提取指定位的系统函数。
get_bit() 在 PostgreSQL 7.0 中被添加。
用法
get_bit (bytesbytea,nbigint ) →integer
请注意,在一个字节内,n 代表从最低位值开始的偏移量。
变更历史
- PostgreSQL 7.0
- 添加 (提交 eca02fee)
请注意,get_bit() 在早期版本中以 byteaGetBit() 的形式存在,但实现不正确。
示例
get_bit() 的基本用法示例
postgres=# SELECT get_bit('\x2a'::bytea, 1);
get_bit
---------
1
(1 row)
postgres=# SELECT get_bit('\x2a'::bytea, 2);
get_bit
---------
0
(1 row)
请注意,2a 等同于位值 00101010
postgres=# SELECT n, get_bit('\x2a'::bytea, n) FROM generate_series(0,7) AS n;
n | get_bit
---+---------
0 | 0
1 | 1
2 | 0
3 | 1
4 | 0
5 | 1
6 | 0
7 | 0
(8 rows)
参考资料
- PostgreSQL 文档: 其他二进制字符串函数
