---
title: position function
description: Learn the syntax of the position function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/position
---

# `position` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns the position of the first occurrence of `substr` in `str` after position `pos`. This function is a synonym for [`locate` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/locate.md).

## Syntax

```
position(substr, str [, pos] )
```

```
position(subtr IN str)
```

## Arguments

* `substr`: A `STRING` expression.
* `str`: A `STRING` expression.
* `pos`: An `INTEGER` expression.

## Returns

An `INTEGER`.

The specified `pos` and return value are 1-based.
If `pos` is omitted, `substr` is searched from the beginning of `str`.
If `pos` is less than 1, the result is 0.

## Examples

```sql
> SELECT position('bar', 'abcbarbar');
 4

> SELECT position('bar', 'abcbarbar', 5);
 7

> SELECT position('bar' IN 'abcbarbar');
 4

> SELECT position('BAR' COLLATE UTF8_BINARY, 'abcbarbar');
 0

> SELECT position('BAR' COLLATE UTF8_LCASE, 'abcbarbar');
 4
```

## Related functions

* [`charindex` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/charindex.md)
* [`instr` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/instr.md)
* [`locate` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/locate.md)
