PostgreSQL LENGTH() function
LENGTH() function
The PostgreSQL length() function is used to find the length of a string i.e. number of characters in the given string.
Syntax:
length(<string>)
PostgreSQL Version: 9.3
Pictorial Presentation of PostgreSQL LENGTH() function

Example: PostgreSQL LENGTH() function:
In the example below the length function returns the length of the given string 'w3resource'.
Code:
SELECT length('w3resource')
AS "Length of a String";
Sample Output:
Length of a String -------------------- 10 (1 row)
Example of PostgreSQL LENGTH() function using column :
Sample Table: employees
The example below, returns the first_name and the length of first_name ( how many characters contain in the first name ) from the employees where the length of first_name is more than 7.
Code:
SELECT first_name,length(first_name)
AS "Length of a First Name"
FROM employees
WHERE length(first_name)>7;
Sample Output:
first_name | Length of a First Name -------------+------------------------ Alexander | 9 Jose Manuel | 11 Alexander | 9 Christopher | 11 Danielle | 8 Harrison | 8 Elizabeth | 9 Jonathon | 8 Kimberely | 9 Jennifer | 8 Jennifer | 8 (11 rows)
Previous: LEFT function
Next: LPAD 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