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

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)
Previous: BIT_LENGTH function
Next: LOWER function
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook