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

# PostgreSQL LTRIM() Function

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `LTRIM()` function to remove specified characters from the beginning of a string.

## Introduction to PostgreSQL LTRIM() function

The `LTRIM()` function allows you to remove specified characters from the beginning of a string.

Here's the syntax of the `LTRIM()` function:

```sql
LTRIM(string, character)
```

In this syntax:

- `string` is the input string that you want to remove characters.
- `character` specifies the characters you want to remove from the beginning of the `string`. The `character` parameter is optional. It defaults to space.

The `LTRIM()` function returns the string with all leading characters removed.

To remove both leading and trailing characters from a string, you use the [TRIM()](https://neon.com/postgresql/postgresql-string-functions/postgresql-trim-function) function.

To remove the trailing characters from a string, you use the [RTRIM()](https://neon.com/postgresql/postgresql-string-functions/postgresql-rtrim) function.

## PostgreSQL LTRIM() function examples

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

### 1) Basic PostgreSQL LTRIM() function example

The following example uses the `LTRIM()` function to remove the `#` from the beginning of the string `#postgres`:

```sql
SELECT LTRIM('#postgres', '#');
```

Output:

```text
  ltrim
----------
 postgres
(1 row)
```

### 2) Using the PostgreSQL LTRIM() function to remove leading spaces

The following example uses the `LTRIM()` function to remove all the spaces from the string `' PostgreSQL'`:

```sql
SELECT LTRIM('   PostgreSQL');
```

Output:

```text
   ltrim
------------
 PostgreSQL
(1 row)
```

Since the default of the second argument of the `LTRIM()` function is space, we don't need to specify it.

### 3) Using the LTRIM() function with table data example

First, [create a new table](../postgresql-tutorial/postgresql-create-table) called `articles` and [insert some rows](../postgresql-tutorial/postgresql-insert-multiple-rows) into it:

```sql
CREATE TABLE articles(
   id SERIAL PRIMARY KEY,
   title VARCHAR(255) NOT NULL
);

INSERT INTO articles(title)
VALUES
   ('   Mastering PostgreSQL string functions'),
   (' PostgreSQL LTRIM() function')
RETURNING *;
```

Output:

```text
 id |                  title
----+------------------------------------------
  1 |    Mastering PostgreSQL string functions
  2 |  PostgreSQL LTRIM() function
(2 rows)
```

Second, [update](../postgresql-tutorial/postgresql-update) the titles by removing the leading spaces using the `LTRIM()` function:

```sql
UPDATE articles
SET title = LTRIM(title);
```

Output:

```sql
UPDATE 2
```

The output indicates that two rows were updated.

Third, verify the updates:

```sql
SELECT * FROM articles;
```

Output:

```text
 id |                 title
----+---------------------------------------
  1 | Mastering PostgreSQL string functions
  2 | PostgreSQL LTRIM() function
(2 rows)
```

## Summary

- Use `LTRIM()` function to remove all specified characters from the beginning 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)
- [LENGTH](https://neon.com/postgresql/postgresql-string-functions/postgresql-length-function)
- [LOWER](https://neon.com/postgresql/postgresql-string-functions/postgresql-lower)
- [LPAD](https://neon.com/postgresql/postgresql-string-functions/postgresql-lpad)
- [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)
