SELECT `justfunctions.eu.extract_url_path`("https://hey.com/me/?parameter=1", True)
/*--Output--
/me/
*/
CREATE OR REPLACE FUNCTION `your_project_id.your_dataset_id.extract_url_path`(`url` STRING, `clean_url_tail` BOOL)
RETURNS STRING AS (CASE WHEN clean_url_tail THEN
SPLIT(SPLIT(SPLIT(url,NET.HOST(url))[SAFE_OFFSET(1)],'?')[SAFE_OFFSET(0)],'#')[SAFE_OFFSET(0)]
ELSE
SPLIT(url,NET.HOST(url))[SAFE_OFFSET(1)]
END)
OPTIONS ( description = '''Extracts the URL path from a <url>, optionally removing the URL tail.''')
SQL User Defined Function (SQL UDF)
See something wrong? Contact us or report an issue on Github.