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

# PostgreSQL POSITION() Function

The PostgreSQL `POSITION()` function returns the location of the first instance of a substring within a string.

## Syntax

The following illustrates the syntax of the `POSITION()` function:

```sql
POSITION(substring in string)
```

## Arguments

The `POSITION()` function requires two arguments:

**1) `substring`**

The substring argument is the string that you want to locate.

**2) `string`**

The `string` argument is the string for which the substring is searched.

## Return Value

The `POSITION()` function returns an [integer](../postgresql-tutorial/postgresql-integer) representing the location of the first instance of the substring within the input string.

The `POSITION()` function returns zero (0) if the substring is not found in the string. It returns NULL if either `substring` or `string` argument is null.

## Examples

The following example returns the position of the `'Tutorial'` in the string `'PostgreSQL Tutorial'`:

```sql
SELECT POSITION('Tutorial' IN 'PostgreSQL Tutorial');
```

The result is as follows:

```sql
position
----------
       12
(1 row)
```

Note that the `POSITION()` function searches for the substring case-insensitively.

See the following example:

```sql
SELECT POSITION('tutorial' IN 'PostgreSQL Tutorial');
```

It returns zero (0), indicating that the string `tutorial` does not exist in the string `'PostgreSQL Tutorial'`.

The following example uses the `POSITION()` function to locate the first string `'fateful'` in the `description` column of the `film` table from the [sample database](../postgresql-getting-started/postgresql-sample-database):

```sql
SELECT
  POSITION('Fateful' in description ),
  description
FROM
  film
WHERE
  POSITION('Fateful' in description ) > 0;
```

Output:

```text
 position |                                                   description
----------+-----------------------------------------------------------------------------------------------------------------
        3 | A Fateful Reflection of a Moose And a Husband who must Overcome a Monkey in Nigeria
        3 | A Fateful Yarn of a Lumberjack And a Feminist who must Conquer a Student in A Jet Boat
        3 | A Fateful Yarn of a Womanizer And a Feminist who must Succumb a Database Administrator in Ancient India
        3 | A Fateful Display of a Womanizer And a Mad Scientist who must Outgun a A Shark in Soviet Georgia
...
```

## Remarks

The `POSITION()` function returns the location of the first instance of the substring in the string.

For example:

```sql
SELECT POSITION('is' IN 'This is a cat');
```

Output:

```
 position
----------
        3
(1 row)
```

Even though the substring `'is'` appears twice in the string `'This is a cat'`, the `POSITION()` function returns the first match.

## Summary

- Use the `POSITION()` function to locate the first instance of a substring within 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)
- [LTRIM](https://neon.com/postgresql/postgresql-string-functions/postgresql-ltrim)
- [MD5](https://neon.com/postgresql/postgresql-string-functions/postgresql-md5)
- [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)
