Request a demo

BigQuery · String function

BigQuery CONTAINS_SUBSTR

CONTAINS_SUBSTR(expression, 'text') returns TRUE if the text appears anywhere in the value, ignoring case and Unicode differences. It also searches every field of a STRUCT, ARRAY or whole row: WHERE CONTAINS_SUBSTR(t, 'timeout') checks all columns.

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

CONTAINS_SUBSTR is BigQuery's "string contains" check. Both sides are normalized with NFKC and case-folded before comparison, so 'FAILED' matches 'failed' and 'Straße' matches 'STRASSE'. There are no wildcards: % and _ are searched for literally.

The first argument doesn't have to be a STRING. Numbers, dates, timestamps and booleans are cast to STRING before the search. For a STRUCT or ARRAY, every field and element is searched recursively, and if you pass a table alias, the row is treated as a STRUCT of all its columns: WHERE CONTAINS_SUBSTR(events, 'timeout') searches every column of events. To limit the search, pass a struct of chosen columns, such as (subject, body). For JSON values, the named argument json_scope chooses between 'JSON_VALUES' (default), 'JSON_KEYS' and 'JSON_KEYS_AND_VALUES'.

The search value must be a literal or a constant expression; you can't pass another column. NULL handling in a cross-field search: TRUE if any field matches, otherwise NULL if any field is NULL, otherwise FALSE. For case-sensitive or pattern matching, use LIKE or REGEXP_CONTAINS.

Syntax

CONTAINS_SUBSTR(expression, search_value_literal[, json_scope => json_scope_value])

Arguments and return value

ArgumentDescription
expressionThe value to search: a column of STRING, INT64, NUMERIC, BIGNUMERIC, BOOL, DATE, DATETIME, TIME, TIMESTAMP, ARRAY, STRUCT or JSON, or a table alias to search the whole row.
search_value_literalThe text to find. Must be a STRING literal or constant expression, not a column, and not NULL.
json_scopeOptional named argument for JSON data: 'JSON_VALUES' (default), 'JSON_KEYS' or 'JSON_KEYS_AND_VALUES'.

Returns: BOOL. NULL if expression is NULL, or if no field matches and at least one field is NULL.

Examples

Case-insensitive and type-agnostic search

SELECT
  CONTAINS_SUBSTR('Payment FAILED: card declined', 'failed') AS ignores_case,
  CONTAINS_SUBSTR('Straße 12', 'STRASSE') AS case_folding,
  CONTAINS_SUBSTR(DATE '2026-11-23', '2026-11') AS date_value,
  CONTAINS_SUBSTR('50% off', '%') AS no_wildcards;
Result
ignores_casecase_foldingdate_valueno_wildcards
truetruetruetrue

Search every column of a row

The first match is in message, the second in job_name. To search only some columns, use CONTAINS_SUBSTR((status, message), 'timeout').

WITH pipeline_runs AS (
  SELECT 'orders_daily' AS job_name, 'SUCCESS' AS status, 'loaded 1200 rows' AS message UNION ALL
  SELECT 'events_hourly', 'FAILED', 'Timeout after 3600s' UNION ALL
  SELECT 'timeout_monitor', 'SUCCESS', 'no stuck jobs'
)
SELECT job_name, status
FROM pipeline_runs
WHERE CONTAINS_SUBSTR(pipeline_runs, 'timeout')
ORDER BY job_name;
Result
job_namestatus
events_hourlyFAILED
timeout_monitorSUCCESS

NULL fields in a cross-field search

Without a match, one NULL field makes the result NULL instead of FALSE. In a WHERE clause both NULL and FALSE filter the row out.

SELECT
  CONTAINS_SUBSTR(STRUCT('api' AS source, CAST(NULL AS STRING) AS detail), 'api') AS match_found,
  CONTAINS_SUBSTR(STRUCT('api' AS source, CAST(NULL AS STRING) AS detail), 'web') AS no_match_with_null;
Result
match_foundno_match_with_null
trueNULL

Common mistakes

  • Passing a column as the search value. CONTAINS_SUBSTR(message, keyword) fails because the second argument must be a constant expression; use STRPOS(LOWER(message), LOWER(keyword)) > 0 to search for per-row values.
  • Using LIKE wildcards. CONTAINS_SUBSTR(name, 'a%b') searches for the literal text a%b.
  • Expecting case-sensitive results. CONTAINS_SUBSTR always ignores case; use STRPOS(value, 'Abc') > 0 or value LIKE '%Abc%' when case matters.
  • Using NOT CONTAINS_SUBSTR(...) on rows with NULL fields. The function can return NULL, and NOT NULL is still NULL, so those rows are dropped from both the match and the non-match set. Wrap it in IFNULL(..., FALSE).

Cost and performance

  • Searching a whole row with CONTAINS_SUBSTR(t, 'x') reads every column of the table, so an on-demand query is billed for all of them. List only the columns you need in a struct to scan fewer bytes.

FAQ

How do I check if a string contains a substring in BigQuery?

Use CONTAINS_SUBSTR(value, 'text') for a case-insensitive check, or value LIKE '%text%' or STRPOS(value, 'text') > 0 for a case-sensitive one.

How do I search all columns of a table in BigQuery?

Pass the table alias: SELECT * FROM my_table AS t WHERE CONTAINS_SUBSTR(t, 'text'). Every column, including nested fields and arrays, is cast to string and searched.

What is the difference between CONTAINS_SUBSTR and LIKE?

LIKE is case-sensitive, supports % and _ wildcards and works on one STRING. CONTAINS_SUBSTR ignores case, has no wildcards, and can search numbers, dates, structs, arrays, JSON and whole rows.

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.