PostgreSQL char_length() Function
The PostgreSQL char_length()
function returns the number of characters in a string. It is a multibyte safe function.
This function is the same as the character_length()
character_length()
function.
char_length()
Syntax
This is the syntax of the PostgreSQL char_length()
function:
char_length(string)
Parameters
string
-
Required. The string whose number of characters needs to count.
Return value
The PostgreSQL char_length()
function is a multibyte-safe function that returns the number of characters in a string.
char_length()
Examples
This example shows how to use the char_length()
function to get the number of characters in a string.
SELECT
char_length('a') AS "a",
char_length('abc') AS "abc",
char_length('Hello World') AS "Hello World";
a | abc | Hello World
---+-----+-------------
1 | 3 | 11
The PostgreSQL char_length()
function is a multibyte-safe function. It also returns correctly if the string contains multibyte characters, such as Chinese.
SELECT char_length('你好') AS "char_length('你好')";
char_length('你好')
---------------------
2