Request a demo

BigQuery · String function

BigQuery STARTS_WITH

STARTS_WITH(value, prefix) returns TRUE if a string begins with prefix: STARTS_WITH(table_name, 'tmp_') is TRUE for tmp_orders. It is case-sensitive and, unlike LIKE 'tmp_%', treats _ and % as plain characters.

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

STARTS_WITH compares the beginning of value with prefix and returns a BOOL. The comparison is exact and case-sensitive. An empty prefix always returns TRUE, and a NULL argument returns NULL, which a WHERE clause treats as not matching.

The main advantage over LIKE 'prefix%' is escaping. In LIKE, _ matches any single character and % any sequence, so table_name LIKE 'tmp_%' also matches tmpx_orders. STARTS_WITH treats every character literally, which suits table names, GCS paths and codes that contain underscores.

For a case-insensitive check, lowercase the value: STARTS_WITH(LOWER(email), 'admin'). For suffixes, use ENDS_WITH; for text anywhere in the string, use CONTAINS_SUBSTR or LIKE.

Syntax

STARTS_WITH(value, prefix)

Arguments and return value

ArgumentDescription
valueThe STRING or BYTES value to test.
prefixThe prefix to look for, the same type as value.

Returns: BOOL. NULL if either argument is NULL.

Examples

Underscores are literal in STARTS_WITH

In LIKE the _ matches the x; it has to be escaped to mean an underscore.

SELECT
  STARTS_WITH('tmpx_orders', 'tmp_') AS starts_with_result,
  'tmpx_orders' LIKE 'tmp_%' AS like_result,
  'tmpx_orders' LIKE r'tmp\_%' AS escaped_like_result;
Result
starts_with_resultlike_resultescaped_like_result
falsetruefalse

Case sensitivity and edge cases

SELECT
  STARTS_WITH('Order-1001', 'order') AS case_sensitive,
  STARTS_WITH(LOWER('Order-1001'), 'order') AS lowercased,
  STARTS_WITH('Order-1001', '') AS empty_prefix,
  STARTS_WITH(CAST(NULL AS STRING), 'O') AS null_value;
Result
case_sensitivelowercasedempty_prefixnull_value
falsetruetrueNULL

Find staging tables

WITH tables AS (
  SELECT 'stg_orders' AS table_name UNION ALL
  SELECT 'stgx_test' UNION ALL
  SELECT 'orders'
)
SELECT table_name
FROM tables
WHERE STARTS_WITH(table_name, 'stg_')
ORDER BY table_name;
Result
table_name
stg_orders

Common mistakes

  • Using LIKE 'prefix_%' for prefixes that contain _ or %. The underscore is a wildcard; use STARTS_WITH or escape it as r'prefix\_%'.
  • Porting Snowflake's STARTSWITH. BigQuery spells it STARTS_WITH, with an underscore; STARTSWITH fails with Function not found.
  • Expecting case-insensitive matching. Compare STARTS_WITH(LOWER(value), 'abc') or use REGEXP_CONTAINS(value, r'(?i)^abc').

Cost and performance

  • On a table with a search index, BigQuery can use the index for STARTS_WITH(column, 'prefix') and column LIKE 'prefix%', but not when the column is wrapped in another function such as SUBSTR.

FAQ

What is the difference between STARTS_WITH and LIKE in BigQuery?

STARTS_WITH(col, 'abc') and col LIKE 'abc%' usually return the same result. STARTS_WITH treats _ and % literally, while LIKE treats them as wildcards unless you escape them.

Is STARTS_WITH case-sensitive?

Yes. Lowercase both sides for a case-insensitive prefix check.

How do I check whether a string starts with one of several prefixes?

Combine with OR, or use a quantified LIKE: col LIKE ANY ('stg\\_%', 'tmp\\_%').

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.