Request a demo

BigQuery · String function

BigQuery SPLIT

SPLIT breaks a string into an ARRAY<STRING> on a delimiter: SPLIT('a,b,c', ',') returns [a, b, c]. Take one part with [OFFSET(n)] or [SAFE_OFFSET(n)], or turn the parts into rows with UNNEST.

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

SPLIT turns a delimited string into an array. The delimiter is a literal string of one or more characters (the default is a comma). It is not a regular expression: to split on a pattern, use REGEXP_EXTRACT_ALL to extract the pieces instead.

An empty delimiter splits the string into single characters, which is the usual way to turn a string into an array of characters. Empty parts are kept: SPLIT('a,,b') has three elements, and splitting an empty string returns an array with one empty string, not an empty array. A NULL input returns a NULL array, which BigQuery shows as [] in query results.

To get one part, index the array: SPLIT(path, '/')[SAFE_OFFSET(1)] is the second part, or NULL if it doesn't exist. This replaces SPLIT_PART from Snowflake, PostgreSQL and Redshift, which BigQuery doesn't have. Plain OFFSET raises an array index out of bounds error when a row has fewer parts. To turn parts into rows, use UNNEST.

Syntax

SPLIT(value[, delimiter])

Arguments and return value

ArgumentDescription
valueThe STRING or BYTES value to split.
delimiterThe literal separator. Defaults to ',' for STRING; required for BYTES. '' splits into single characters (STRING) or bytes (BYTES).

Returns: ARRAY<STRING> or ARRAY<BYTES>. NULL if value or delimiter is NULL.

Examples

Split, take a part, take the last part

The double slash in gs:// produces an empty element, so the bucket name is at offset 2, not 1.

SELECT
  SPLIT('gs://exports/2026/11/orders.csv', '/') AS parts,
  SPLIT('gs://exports/2026/11/orders.csv', '/')[SAFE_OFFSET(2)] AS bucket,
  ARRAY_LAST(SPLIT('gs://exports/2026/11/orders.csv', '/')) AS file_name;
Result
partsbucketfile_name
[gs:, , exports, 2026, 11, orders.csv]exportsorders.csv

String to array of characters

SELECT SPLIT('SKU42', '') AS characters;
Result
characters
[S, K, U, 4, 2]

Empty strings and NULLs

SELECT
  ARRAY_LENGTH(SPLIT('', ',')) AS parts_in_empty_string,
  TO_JSON_STRING(SPLIT('red,,blue,', ',')) AS empty_parts_kept,
  SPLIT(CAST(NULL AS STRING), ',') IS NULL AS null_input;
Result
parts_in_empty_stringempty_parts_keptnull_input
1["red","","blue",""]true

One row per tag

LEFT JOIN UNNEST keeps orders whose array is NULL or empty; a comma join (FROM orders, UNNEST(...)) would drop order 1003.

WITH orders AS (
  SELECT 1001 AS order_id, 'gift,express' AS tags UNION ALL
  SELECT 1002, 'express' UNION ALL
  SELECT 1003, CAST(NULL AS STRING)
)
SELECT order_id, TRIM(tag) AS tag
FROM orders
LEFT JOIN UNNEST(SPLIT(tags, ',')) AS tag
ORDER BY order_id, tag;
Result
order_idtag
1001express
1001gift
1002express
1003NULL

Common mistakes

  • Using [OFFSET(n)] on data with a variable number of parts. One short row fails the whole query with Array index n is out of bounds. Use [SAFE_OFFSET(n)], which returns NULL.
  • Passing a regex as the delimiter. SPLIT('a1b2c', r'\d') returns the input unchanged as one element. Use REGEXP_EXTRACT_ALL(value, r'[^0-9]+') to split on a pattern.
  • Expecting SPLIT_PART. BigQuery has no SPLIT_PART (Snowflake, PostgreSQL, Redshift). SPLIT_PART(s, ',', 2) becomes SPLIT(s, ',')[SAFE_OFFSET(1)]: OFFSET is 0-based, SAFE_ORDINAL is 1-based.
  • Forgetting to trim. SPLIT('a, b', ',') returns a and b with a leading space. Apply TRIM to each element.
  • Losing rows with a comma join. FROM t, UNNEST(SPLIT(col)) drops rows where col is NULL. Use LEFT JOIN UNNEST(...).

FAQ

How do I convert a string to an array in BigQuery?

Use SPLIT(value, delimiter) for delimited text, SPLIT(value, '') for an array of characters, and REGEXP_EXTRACT_ALL(value, pattern) when the parts are defined by a regular expression.

How do I get the last element after SPLIT?

Use ARRAY_LAST(SPLIT(value, '/')), or ARRAY_REVERSE(SPLIT(value, '/'))[SAFE_OFFSET(0)].

How do I split a string into rows?

Cross join the array with UNNEST: SELECT id, part FROM t, UNNEST(SPLIT(col, ',')) AS part. Add WITH OFFSET AS pos after the alias to keep each part's position.

What is the BigQuery equivalent of SPLIT_PART?

SPLIT(value, delimiter)[SAFE_OFFSET(n - 1)], or [SAFE_ORDINAL(n)] to keep 1-based numbering. Both return NULL when the part doesn't exist.

Errors you may hit

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.