Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all characters after a certain character in BigQuery using standard SQL?

I have a list of URLs/ Here is an example — www.site.com/product/item1/?utm_source=google&utm_medium=cpc

How I can get all characters before question mark using BigQuery? Sо I want to get www.site.com/product/item1/ from this string.

Thanks a lot!

like image 538
Serge Avatar asked Sep 04 '25 16:09

Serge


1 Answers

The easiest way I think is to use SPLIT function as in below example

SPLIT(url, '?')[OFFSET(0)]    

As alternative, you can use REGEXP_EXTRACT as in below example

REGEXP_EXTRACT(url, r'[^?]*')
like image 54
Mikhail Berlyant Avatar answered Sep 07 '25 17:09

Mikhail Berlyant