PostgreSQL position() Function
The PostgreSQL position()
function returns the starting index of a specified substring within a specified string.
The position()
function is the same as a strpos()
function, but the order of the arguments is different.
position()
Syntax
This is the syntax of the PostgreSQL position()
function:
position(substring IN string)
position(substring IN string)
is equivalent to strpos(string, substring)
.
Parameters
substring
-
Required. The substring to search for.
string
-
Required. The string to search within.
Return value
The PostgreSQL position()
function returns the starting index of the substring substring
within the string string
. This function returns 0 if the substring substring
is not present in the string string
.
If the parameter is NULL
, the function will return NULL
.
position()
Examples
This example shows how to use the position()
function to get the starting index of a substring in a string.
SELECT position('world' IN 'hello world');
position
----------
7