extract_url_path(url, clean_url_tail)
Extracts the URL path from a <url>, optionally removing the URL tail.
CREATE OR REPLACE FUNCTION `justfunctions.eu.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.''')
Example
SELECT `justfunctions.eu.extract_url_path`("https://hey.com/me/?parameter=1", True)
/me/