Function Reference

OCTET_LENGTH

Returns the size of a string in bytes.

PostgreSQL 17.5
OCTET_LENGTH(string)

Parameters

stringtext
Source string

Return value

An integer, the number of bytes

Examples

Bytes and characters

PostgreSQL 17.5
SELECT OCTET_LENGTH('привет') AS bytes,
	CHAR_LENGTH('привет') AS chars,
	OCTET_LENGTH('hello') AS latin_bytes;
bytescharslatin_bytes
1265

Size of names in bytes

PostgreSQL 17.5
SELECT member_name,
	OCTET_LENGTH(member_name) AS bytes
FROM FamilyMembers;
member_namebytes
Headley Quincey15
Flavia Quincey14
Andie Quincey13
Lela Quincey12
Annie Quincey13
Ernest Forrest14
Constance Forrest17
Wednesday Addams16

Details

In UTF-8 a Latin letter takes 1 byte and a Cyrillic letter takes 2, so for Russian text the result is larger than that of CHAR_LENGTH. In MySQL bytes are counted by LENGTH.

See also