Function Reference

POSITION

MySQL equivalent:

Returns the position of the first occurrence of a substring in a string.

PostgreSQL 17.9
POSITION(substring IN string)
substring
Substring to find
text
IN string
String to search in
text

Return value

An integer position starting from 1; 0 if the substring is not found; case-sensitive

Examples

Position of a substring

PostgreSQL 17.9
SELECT POSITION('om' IN 'Thomas');
position
3

Case-sensitive search

PostgreSQL 17.9
SELECT POSITION('sql' IN 'PostgreSQL');
position
0

Details

To search ignoring case, convert both strings to the same case: POSITION(LOWER('SQL') IN LOWER(string)). STRPOS(string, substring) does the same with the usual comma-separated arguments.

See also

Where to learn