Function Reference

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');
strpos
5

Position of the space in a name

PostgreSQL 17.5
SELECT member_name,
	STRPOS(member_name, ' ') AS space_position
FROM FamilyMembers;
member_namespace_position
Headley Quincey8
Flavia Quincey7
Andie Quincey6
Lela Quincey5
Annie Quincey6
Ernest Forrest7
Constance Forrest10
Wednesday Addams10

Details

STRPOS is the same as POSITION(substring IN string), but the arguments go in reverse order.

See also