BIT_LENGTH

Returns the length of the string expression in bits (bytes * 8) as an INTEGER.

Returns the length of the string expression in bits (bytes * 8) as an INTEGER. BIT_LENGTH applies to the contents of VARCHAR and VARBINARY fields.

Behavior type

Immutable

Syntax

BIT_LENGTH ( expression )

Arguments

expression
(CHAR or VARCHAR or BINARY or VARBINARY) is the string to convert.

Examples

Expression Result
SELECT BIT_LENGTH('abc'::varbinary); 24
SELECT BIT_LENGTH('abc'::binary); 8
SELECT BIT_LENGTH(''::varbinary); 0
SELECT BIT_LENGTH(''::binary); 8
SELECT BIT_LENGTH(null::varbinary);
SELECT BIT_LENGTH(null::binary);
SELECT BIT_LENGTH(VARCHAR 'abc'); 24
SELECT BIT_LENGTH(CHAR 'abc'); 24
SELECT BIT_LENGTH(CHAR(6) 'abc'); 48
SELECT BIT_LENGTH(VARCHAR(6) 'abc'); 24
SELECT BIT_LENGTH(BINARY(6) 'abc'); 48
SELECT BIT_LENGTH(BINARY 'abc'); 24
SELECT BIT_LENGTH(VARBINARY 'abc'); 24
SELECT BIT_LENGTH(VARBINARY(6) 'abc'); 24

See also