Function Reference

CHAR_LENGTH

Returns the number of characters in a string.

PostgreSQL 17.5
CHAR_LENGTH(string)

Parameters

stringtext
Source string

Return value

An integer, the number of characters, not bytes

Examples

Characters and bytes in a Cyrillic string

PostgreSQL 17.5
SELECT CHAR_LENGTH('привет') AS char_length,
	OCTET_LENGTH('привет') AS byte_length;
char_lengthbyte_length
612

Names longer than 13 characters

PostgreSQL 17.5
SELECT member_name,
	CHAR_LENGTH(member_name) AS name_length
FROM FamilyMembers
WHERE CHAR_LENGTH(member_name) > 13;
member_namename_length
Headley Quincey15
Flavia Quincey14
Ernest Forrest14
Constance Forrest17
Wednesday Addams16

Details

It is a synonym for LENGTH: unlike in MySQL, where LENGTH counts bytes, both functions count characters. The size of a string in bytes is returned by OCTET_LENGTH.

See also