Skip to main content

STRPOS

Functions › Text › Find

Returns the position of the first occurrence of a substring, counting from 1, or 0 when it is not found.

Syntax​

STRPOS( <string>, <substring> )

Arguments​

ArgumentDescription
<string>The text to search.
<substring>The text to find. Matched exactly, with case.

Returns​

An integer: the character position of the first match, or 0 when there is none. 1 when <substring> is empty. NULL when any argument is NULL.

Usage notes​

  • POSITION is the standard form with the arguments the other way round: POSITION(<substring> IN <string>).
  • The position counts characters, not bytes.
  • On large tables the engine runs it in the data store.

Examples​

SELECT f.name, STRPOS(f.name, '.') AS dot
FROM tables.drive.file f
WHERE STRPOS(f.name, 'draft') > 0
namedot
draft_plan.docx11

With SUBSTRING, take the text before a character:

SELECT c.email, SUBSTRING(c.email, 1, STRPOS(c.email, '@') - 1) AS mailbox FROM Customer c
emailmailbox
ana.ruiz@example.comana.ruiz

See also​

POSITION · SUBSTRING · SPLIT_PART · STARTS_WITH · LIKE