Amy123
Amy123

Reputation: 972

Redshift - Split column to find value between delimiter with uncertain position

I have a table in redshift with two columns, id and link.

Current Table

id link

1 www.something.com/bla?lughlegh &fruit=apple& khkhflkjndkj&ljghldh&ljhrleh

2 www.somethingelse.com/blabla?sdf&hthdth&sdhfhfY &fruit=orange& ergegertg

I want to pick the value fruit=apple from the link column. But the catch is -

I have to basically look for the text fruit= and pick values between fruit= and the next &

Required table

id link fruit

1 www.something.com/bla?lughlegh &fruit=apple& khkhflkjndkj&ljghldh&ljhrleh apple

2 www.somethingelse.com/blabla?sdf&hthdth&sdhfhfY &fruit=orange& ergegertg orange

Upvotes: 0

Views: 285

Answers (1)

Bohemian
Bohemian

Reputation: 425033

Try REGEXP_REPLACE:

REGEXP_REPLACE(url, ".*[?&]fruit=([^&]*).*", "$1");

Upvotes: 1

Related Questions