STRPOS
MySQL equivalent:
Returns the position of the first occurrence of a substring in a string.
PostgreSQL 17.5
STRPOS(string, substring)Parameters
- stringtext
- String to search in
- substringtext
- Substring to find
Return value
An integer position starting from 1; 0 if the substring is not found; case-sensitive
Examples
Position of a substring
PostgreSQL 17.5
SELECT STRPOS('sql-academy', 'academy');Position of the space in a name
PostgreSQL 17.5
SELECT member_name,
STRPOS(member_name, ' ') AS space_position
FROM FamilyMembers;Details
STRPOS is the same as POSITION(substring IN string), but the arguments go in reverse order.