0

How would I go about extracting a specific part of the path using PARSE_URL? For example, if I query...

> WITH cte AS (   
> SELECT CONCAT('http://', COLUMN1) AS URL   FROM VALUES
>      ('www.url1.com/test'), 
>      ('www.url1.com/test2/'), 
>      ('www.url1.com/test/sub_test/') ) 
> SELECT URL, 
>        PARSE_URL(URL) AS parts,
>        PARSE_URL(URL):path::text AS path,
>        TRIM(PARSE_URL(URL):path::text, '/') AS path
> FROM cte;

For www.url1.com/test/sub_test, the path is test/sub_test, but how would I extract just sub_test?

greeble
  • 31
  • 4
  • https://joshdevlin.com/blog/parse-url-snowflake/ might be useful, `parse_url(url):path::varchar` then locate the second `/`. don't think `parse_url` can be used to return part path – user3783243 Jun 04 '22 at 00:21
  • 1
    Try this - split_part(TRIM(PARSE_URL(URL):path::text, '/'),'/',-1) – Pankaj Jun 04 '22 at 00:40

1 Answers1

-5

Use SELECT RIGHT for it, man. Just you have to find last "/" position