bit_length()

A function returning the number of bits in the provided parameter

bit_length() is a system function which returns the number of bits in the provided parameter.

bit_length() was added in PostgreSQL 7.2.

Usage

bit_length ( bit ) → integer
bit_length ( bytea ) → integer
bit_length ( text ) → integer

Change history

Examples

Number of bits in a simple ASCII string:

postgres=# SELECT bit_length('ABC');
 bit_length 
------------
         24
(1 row)

Number of bits in an UTF8 string containing multibyte characters:

postgres=# SELECT bit_length('ほげほげ');
 bit_length 
------------
         96
(1 row)

Number of bits in a bit string:

postgres=# SELECT bit_length(B'10101');
 bit_length 
------------
          5
(1 row)

Number of bits in a binary string:

postgres=# SELECT bit_length('\xdeadbeef'::bytea);
 bit_length 
------------
         32
(1 row)

Categories

System function

See also

length(), octet_length()