Request a demo

BigQuery · String function

BigQuery STRPOS

STRPOS(value, subvalue) returns the 1-based position of the first occurrence of subvalue, or 0 if it isn't found: STRPOS('ana@example.com', '@') returns 4. Use it with SUBSTR to cut strings at a delimiter.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

STRPOS searches value for the literal text subvalue and returns where the first match starts, counting characters from 1. It returns 0 when there is no match and NULL when either argument is NULL. The search is case-sensitive and doesn't support wildcards.

The most common use is as an input to SUBSTR, LEFT or RIGHT: find the @ in an email, then take the part before or after it. Because a missing delimiter returns 0, check the result before you compute a length from it.

For the second or the last occurrence, use INSTR, which adds position and occurrence arguments. To test only whether text is present, STRPOS(value, x) > 0 works, but CONTAINS_SUBSTR (case-insensitive) or LIKE '%x%' read more clearly.

Syntax

STRPOS(value, subvalue)

Arguments and return value

ArgumentDescription
valueThe STRING or BYTES value to search.
subvalueThe literal text to find, the same type as value.

Returns: INT64: the 1-based position of the first match, 0 if there is none, NULL if an argument is NULL.

Examples

Position, no match and case sensitivity

The capital E at position 1 doesn't match e.

SELECT
  STRPOS('ana@example.com', '@') AS at_sign,
  STRPOS('ana@example.com', '#') AS missing,
  STRPOS('Example', 'e') AS lowercase_e;
Result
at_signmissinglowercase_e
407

Split an email into user and domain

Without the IF, LEFT(email, -1) would fail on the row without @.

WITH users AS (
  SELECT 'maria.garcia@example.com' AS email UNION ALL
  SELECT 'not-an-email'
)
SELECT
  email,
  IF(STRPOS(email, '@') > 0, LEFT(email, STRPOS(email, '@') - 1), NULL) AS user_name,
  IF(STRPOS(email, '@') > 0, SUBSTR(email, STRPOS(email, '@') + 1), NULL) AS domain
FROM users
ORDER BY email;
Result
emailuser_namedomain
maria.garcia@example.commaria.garciaexample.com
not-an-emailNULLNULL

Common mistakes

  • Using the result as a length without checking for 0. LEFT(email, STRPOS(email, '@') - 1) fails with Second argument in LEFT() cannot be negative on rows without @.
  • Porting the argument order from SQL Server. CHARINDEX(substring, string) takes the substring first; STRPOS takes the string first, like PostgreSQL's STRPOS and MySQL's INSTR(str, substr).
  • Expecting case-insensitive search. Compare STRPOS(LOWER(value), 'abc') if case shouldn't matter.
  • Looking for POSITION, CHARINDEX or LOCATE. BigQuery has STRPOS and INSTR.

FAQ

How do I find the position of a character in a string in BigQuery?

Use STRPOS(value, 'x') for the first occurrence. For the last occurrence, use INSTR(value, 'x', -1).

What does STRPOS return when the substring isn't found?

0, not NULL. It returns NULL only when one of the arguments is NULL.

What is the difference between STRPOS and INSTR?

STRPOS takes two arguments and finds the first match. INSTR also accepts a start position (negative to search backwards) and an occurrence number.

More string functions

All BigQuery string functions · All functions · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.