position function

Returns the position of the first occurrence of substr in str after position pos.

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.

This function is a synonym for locate function.

Examples

> SELECT position('bar', 'foobarbar');
 4
> SELECT position('bar', 'foobarbar', 5);
 7
> SELECT position('bar' IN 'foobarbar');
 4