charindex function at big query

Viewed 9077

I have below sql query and need to run at bigquery

select replace(substring(p.name, charindex(',', p.name), len(p.name)), ',', '') AS [First_Name] from people p

so I have tried below big query syntax

select replace(SUBSTR(p.name, charindex(',', p.name), len(p.name)), ',', '') AS [First_Name] from people

but i am getting below error

Function not found: charindex at [1:1]
1 Answers

BigQuery has much more powerful string manipulation functions than SQL Server. A simpler method is:

select (split(p.name, ','))[safe_ordinal(1)]

You can also use regular expressions:

select regexp_extract(p.name, '[^,]*')
Related