PostgreSQL CHAR_LENGTH() function

CHAR_LENGTH() function

The PostgreSQL char_length function or character_length function is used to count the number of characters in a specified string. The CHARACTER_LENGTH() function is similar to CHAR_LENGTH() function.


char_length (string)


Name Description
string A string whose length is to be retrieved.

PostgreSQL Version: 9.3

Pictorial Presentation of PostgreSQL CHAR_LENGTH() function

PostgreSQL CHAR_LENGTH() function pictorial presentation

Example: PostgreSQL CHAR_LENGTH() function


SELECT char_length('w3resource') AS "Length of a String";

Sample Output:

 Length of a String
(1 row)

PostgreSQL CHAR_LENGTH() function using Column :

Sample Table: employees.

If we want to display the first name, last name and concatenate of first name and last name and number of character after concatenation of those employee who belong to the dept 20 from the employee table, the following SQL can be executed:


SELECT first_name,last_name,
first_name||' '||last_name AS "Name of Employee",
char_length(first_name||' '||last_name ) AS "Length of Name"
FROM employees
WHERE department_id=20;

Sample Output:

 first_name | last_name | Name of Employee  | Length of Name
 Michael    | Hartstein | Michael Hartstein |             17
 Pat        | Fay       | Pat Fay           |              7
(2 rows)

Previous: BIT_LENGTH function
Next: LOWER function

Follow us on Facebook and Twitter for latest update.