0

I have a table in redshift running PostgreSQL in which one of the columns is url.

I need to extract parameters from this url.

ie. if url=foo.bar?param1=a&param2=b&param1=c

I need the value of param1 which is c from this url

Tried a few solutions like

(string_to_array(url,'param1='))[array_upper(string_to_array(url,'param1='),1)]

and

regexp_matches

Redshift does not allow arrays, so both methods are useless. Is there a way to solve this using SQL ?

1
  • 1
    I think you need a regex like param1=([^&=\s]+)(?!.*param1) ;). Commented Oct 11, 2015 at 11:27

1 Answer 1

1

Try to use regexp_matches like this:

SELECT regexp_matches('url=foo.bar?param1=a&param2=b&param1=c', E'param1=([^&=\s]+)(?!.*param1)');

[SQL Fiddle Demo]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.