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;Size of names in bytes
PostgreSQL 17.5
SELECT member_name,
OCTET_LENGTH(member_name) AS bytes
FROM FamilyMembers;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.