Parsing URL for Specific Part of Path

207 Views Asked by At

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?

1

There are 1 best solutions below

0
Bartłomiej Stasiak On

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