> This page location: String Functions > LENGTH
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL LENGTH() Function

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `LENGTH()` functions to get the number of characters of a string.

## Introduction to the PostgreSQL LENGTH() function

The PostgreSQL `LENGTH()` function returns the number of characters in a string.

Here's the basic syntax for the `LENGTH()` function:

```sql
LENGTH(string);
```

The `LENGTH()` function accepts a string as a parameter. It can be any of the following [data types](../postgresql-tutorial/postgresql-data-types):

- character or char
- character varying or varchar
- text

The `LENGTH()` function returns an integer that represents the number of characters in the string. It returns NULL if the string is null.

PostgreSQL provides the `CHAR_LENGTH()` and `CHARACTER_LENGTH()` functions that provide the same functionality as the `LENGTH()` function.

## PostgreSQL LENGTH() function examples

Let's explore some examples of using the `LENGTH()` function.

### 1) Basic PostgreSQL LENGTH() function examples

The following example uses the `LENGTH()` function to get the length of a string:

```sql
SELECT
  LENGTH ('PostgreSQL Tutorial');
```

Output:

```text
 length
--------
     19
(1 row)
```

If you pass NULL to the `LENGTH()` function, it returns NULL.

```sql
SELECT
  LENGTH (NULL);
```

Output:

```text
 length
--------
   null
(1 row)
```

### 2) Using the PostgreSQL LENGTH() function with table data example

We'll use the `customer` table from the [sample database](../postgresql-getting-started/postgresql-sample-database):

![customer table](https://neon.com/postgresqltutorial/customer.png)The following example uses the `LENGTH()` function to retrieve the first names and the number of characters of first names from the `customer` table:

```sql
SELECT
  first_name,
  LENGTH (first_name) len
FROM
  customer
ORDER BY
  len;
```

Output:

```
 first_name  | len
-------------+-----
 Jo          |   2
 Sam         |   3
 Roy         |   3
 Eva         |   3
 Don         |   3
 Dan         |   3
...
```

## Summary

- Use the PostgreSQL `LENGTH()` function to get the number of characters of a string.

---

## Related docs (String Functions)

- [ASCII](https://neon.com/postgresql/postgresql-string-functions/postgresql-ascii)
- [CHR](https://neon.com/postgresql/postgresql-string-functions/postgresql-chr)
- [CONCAT](https://neon.com/postgresql/postgresql-string-functions/postgresql-concat-function)
- [CONCAT_WS](https://neon.com/postgresql/postgresql-string-functions/postgresql-concat_ws)
- [FORMAT](https://neon.com/postgresql/postgresql-string-functions/postgresql-format)
- [INITCAP](https://neon.com/postgresql/postgresql-string-functions/postgresql-initcap)
- [LEFT](https://neon.com/postgresql/postgresql-string-functions/postgresql-left)
- [LOWER](https://neon.com/postgresql/postgresql-string-functions/postgresql-lower)
- [LPAD](https://neon.com/postgresql/postgresql-string-functions/postgresql-lpad)
- [LTRIM](https://neon.com/postgresql/postgresql-string-functions/postgresql-ltrim)
- [MD5](https://neon.com/postgresql/postgresql-string-functions/postgresql-md5)
- [POSITION](https://neon.com/postgresql/postgresql-string-functions/postgresql-position)
- [REGEXP_MATCHES](https://neon.com/postgresql/postgresql-string-functions/postgresql-regexp_matches)
- [REGEXP_REPLACE](https://neon.com/postgresql/postgresql-string-functions/regexp_replace)
- [REPEAT](https://neon.com/postgresql/postgresql-string-functions/postgresql-repeat)
- [REVERSE](https://neon.com/postgresql/postgresql-string-functions/postgresql-reverse)
- [REPLACE](https://neon.com/postgresql/postgresql-string-functions/postgresql-replace)
- [RIGHT](https://neon.com/postgresql/postgresql-string-functions/postgresql-right)
- [RPAD](https://neon.com/postgresql/postgresql-string-functions/postgresql-rpad)
- [RTRIM](https://neon.com/postgresql/postgresql-string-functions/postgresql-rtrim)
- [SPLIT_PART](https://neon.com/postgresql/postgresql-string-functions/postgresql-split_part)
- [SUBSTRING](https://neon.com/postgresql/postgresql-string-functions/postgresql-substring)
- [TO_CHAR](https://neon.com/postgresql/postgresql-string-functions/postgresql-to_char)
- [TO_NUMBER](https://neon.com/postgresql/postgresql-string-functions/postgresql-to_number)
- [TRANSLATE](https://neon.com/postgresql/postgresql-string-functions/postgresql-translate)
- [TRIM](https://neon.com/postgresql/postgresql-string-functions/postgresql-trim-function)
- [UPPER](https://neon.com/postgresql/postgresql-string-functions/postgresql-upper)
