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

# PostgreSQL LEFT() Function

The PostgreSQL `LEFT()` function returns the first `n` characters in the string.

## Syntax

The following illustrates the syntax of the PostgreSQL `LEFT()` function:

```sql
LEFT(string, n)
```

## Arguments

The PostgreSQL `LEFT()` function requires two arguments:

**1) `string`**

is a string from which a number of the leftmost characters returned.

**2) `n`**

is an integer that specifies the number of left-most characters in the string should be returned.

If `n` is negative, the `LEFT()` function returns the leftmost characters in the string but last `|n|` (absolute) characters.

## Return value

The PostgreSQL `LEFT()` function returns the first `n` characters in a string.

## Examples

Let's look at some examples of using the `LEFT()` function.

The following example shows how to get the first character of a string `'ABC'`:

```sql
SELECT LEFT('ABC',1);
```

The result is

```text
 left
------
 A
(1 row)
```

To get the first two characters of the string 'ABC', you use 2 instead of 1 for the `n` argument:

```sql
SELECT LEFT('ABC',2);
```

Here is the result:

```text
 left
------
 AB
(1 row)
```

The following statement demonstrates how to use a negative integer:

```sql
SELECT LEFT('ABC',-2);
```

In this example, n is -2, therefore, the `LEFT()` function return all character except the last 2 characters, which results in:

```
 left
------
 A
(1 row)
```

See the following customer table in the sample database:

The following statement uses the `LEFT()` function to get the initials and the `COUNT()` function to return the number of customers for each initial.

```sql
SELECT LEFT(first_name, 1) initial,
    COUNT(*)
FROM customer
GROUP BY initial
ORDER BY initial;
```

In this example, first, the `LEFT()` function returns initials of all customers. Then, the [`GROUP BY`](../postgresql-tutorial/postgresql-group-by) clause groups customers by their initials. Finally, the [`COUNT()`](../postgresql-aggregate-functions/postgresql-count-function) function returns the number of customer for each group.

![PostgreSQL LEFT example](https://neon.com/postgresqltutorial/PostgreSQL-LEFT-example.png)

## Remarks

If you want to get the `n` rightmost characters, please see the [`RIGHT()`](https://neon.com/postgresql/postgresql-string-functions/postgresql-right) function for the details.

In this tutorial, you have learned how to use the PostgreSQL `LEFT()` function to get the n left-most characters in 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)
- [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)
- [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)
