w3resource
MySQL Tutorial

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.

Syntax:

char_length (string)

Parameters:

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

Code:

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

Sample Output:

 Length of a String
--------------------
                 10
(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:

Code:

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)


New Content: Composer: Dependency manager for PHP, R Programming