Skip to content
Advertisement

How can I remove characters in a string after a specific special character in snowflake sql?

I have a url column in my database. I want to remove all characters after ? .

select regexp_replace(page_url,'?(.*)', '') as clean_url from demo

But I’m getting the following error: Invalid regular expression: ‘?(.*)’, no argument for repetition operator: ?

Advertisement

Answer

Using LEFT and CHARINDEX:

SELECT IFF(CHARINDEX('?', page_url)>0,
           LEFT(page_url, CHARINDEX('?', page_url)),
           page_url) AS clean_url 
FROM demo
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement