> For the complete documentation index, see [llms.txt](https://til.duyet.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.duyet.net/db/google-bigquery/bigquery-split-string-and-get-the-first-part.md).

# BigQuery - Split string and get the first part

Using `SPLIT(value[, delimiter])` returns an array.

Then using `SAFE_OFFSET(zero_based_offset)` or `SAFE_ORDINAL(one_based_offset)` to get item from array.

```sql
SELECT SPLIT(app_info.version, '-')[SAFE_OFFSET(0)] as app_version
FROM ...
```

References:

* <https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#split>
* <https://cloud.google.com/bigquery/docs/reference/standard-sql/array_functions#safe_offset_and_safe_ordinal>
